lite_ref
A lightweight dependency injection package with support for overriding for testing.
0.8.1
4.1K downloads/mo
#4145 most downloaded on pub.dev
jinyus/lite_ref
What this package is like to depend on
Last release 2 years ago
no release in 18 months
Release timing varies
gaps range from 8 days to 2 months
Nearly every release is documented
notes for 18 of 18 stable releases
Nothing withdrawn
no release was ever pulled
3 years old
18 releases · first in 2024
0 releases in the last 12 months
see the full history below
Release timeline
18 releases · Jan 2024 to Apr 2024Releases
latest 18-
0.8.120 Apr 2024 -
0.8.019 Apr 2024Release notes
Open source →-
[Fix] Fixed bug with hot-reloading
-
[Feat] Add
Ref.scopedFamilywhich takes a argument to create a unique instance for each key.-
Create a
ScopedFamilyRef.final postControllerRef = Ref.scopedFamily((ctx, String key) { return PostController(key)..fetch(); }); -
Access the instance in the current scope:
This can be done in a widget by using
postController.of(context, key)orpostController(context, key).class PostsPage extends StatelessWidget { const PostsPage({required this.keys, super.key}); final List<String> keys; @override Widget build(BuildContext context) { return ListView.builder( itemBuilder: (context, index) { final post = postControllerRef.of(context, keys[index]); return Text(post?.title ?? 'Loading...'); }, ); } }
-
-
-
0.7.002 Apr 2024Release notes
Open source →What's Changed
- Add ScopedRef.read(context) by @JinyuS in #19
- Feat: Add onlyOverrides param to LiteRefScope by @JinyuS in #20
- Refactor scoped ref and scope widget to improve performance by @JinyuS in #21
- Fix: bug where refs were disposed when child widget was temporarily deactivated by @JinyuS in #23
Full Changelog: v0.6.1...v0.7.0
Release notes
Open source →-
[Fix] Fixed bug where refs were disposed when the child is temporarily deactivated.
-
[Breaking] The
overridesproperty ofLiteRefScopeis now a Set ofScopedRefs instead of a List ofScopedRefs.Before
LiteRefScope( overrides: [ settingsServiceRef.overrideWith((ctx) => MockSettingsService()), ] child: MyApp(), )After:
LiteRefScope( overrides: { settingsServiceRef.overrideWith((ctx) => MockSettingsService()), } child: MyApp(), )
-
0.6.322 Mar 2024 -
0.6.221 Mar 2024Release notes
Open source →- [Feat] Add
onlyOverridestoLiteRefScopewhich will only provide overridden instances to children.
- [Feat] Add
-
0.6.114 Mar 2024Release notes
Open source →- [Feat] Add
ScopedRef.exists(context)method to check if a ScopedRef is initialized in the current LiteRefScope.
- [Feat] Add
-
0.6.013 Mar 2024 -
0.5.206 Mar 2024 -
0.5.104 Mar 2024Release notes
Open source →- [Fix] Remove
disposefunction when overriding withautoDisposeset tofalse.
- [Fix] Remove
-
0.5.004 Mar 2024Release notes
Open source →-
[Feat] Add autodipose for
ChangeNotifiersand any class that implementsDisposable. These classes will be disposed when all the widgets that have access to the instance are unmounted. If providing a existing and you don't want the instance to be disposed setautoDisposetofalse.In the example below, the
CounterControllerwill be disposed when theCounterViewis unmounted.class CounterController extends ChangeNotifier { var _count = 0; int get count => _count; void increment() { _count++; notifyListeners(); } void decrement() { _count--; notifyListeners(); } } final countControllerRef = Ref.scoped((ctx) => CounterController()); class CounterView extends StatelessWidget { const CounterView({super.key}); @override Widget build(BuildContext context) { final contoller = countControllerRef.of(context); return ListenableBuilder( listenable: contoller, builder: (context, snapshot) { return Text('${contoller.count}'); }, ); } }
-
-
0.4.101 Mar 2024 -
0.4.029 Feb 2024Release notes
Open source →What's Changed
Full Changelog: https://github.com/jinyus/lite_ref/commits/v0.4.0
Release notes
Open source →-
[Breaking] This now a flutter package
-
Add
ScopedRefwhich is a ref that needs a context to access its instance -
Add
LiteRefScopewhich coupled withScopedRefis an alternative toProviderfor classes that don't rebuild widgets.-
Wrap your app or a subtree with a
LiteRefScope:runApp( LiteRefScope( child: MyApp(), ), ); -
Create a
ScopedRef.final settingsServiceRef = Ref.scoped((ctx) => SettingsService()); -
Access the instance in the current scope:
This can be done in a widget by using
settingsServiceRef.of(context)orsettingsServiceRef(context).class SettingsPage extends StatelessWidget { const SettingsPage({super.key}); @override Widget build(BuildContext context) { final settingsService = settingsServiceRef.of(context); return Text(settingsService.getThemeMode()); } } -
Override it for a subtree:
You can override the instance for a subtree by using
overrideWith. This is useful for testing. In the example below, all calls tosettingsServiceRef.of(context)will returnMockSettingsService.LiteRefScope( overrides: [ settingsServiceRef.overrideWith((ctx) => MockSettingsService()), ] child: MyApp(), ),
-
-
-
0.3.007 Jan 2024Release notes
Open source →- Make the factory function non-nullable (improves performance and maintainability)
-
0.2.106 Jan 2024Release notes
Open source →- Internal performance improvements
- fix minor bug where async singleton would not be replace when overridden
-
0.2.006 Jan 2024Release notes
Open source →- separate singleton and transient instantiation use:
Ref.singleton,Ref.transient,Ref.asyncSingletonandRef.asyncTransient - add
assertInstancegetter for synchronous access to a AsyncSingletonRef
- separate singleton and transient instantiation use:
-
0.1.006 Jan 2024Release notes
Open source →- prevent race condition when fetching async singleton
- add
assertInstancegetter for synchronous access to a LiteAsyncRef - add
.freeze()method which disables overriding
-
0.0.206 Jan 2024 -
0.0.106 Jan 2024