lite_ref 0.4.0
lite_ref: ^0.4.0 copied to clipboard
A lightweight dependency injection package with support for overriding for testing.
0.4.0 #
-
[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.0 #
- Make the factory function non-nullable (improves performance and maintainability)
0.2.1 #
- Internal performance improvements
- fix minor bug where async singleton would not be replace when overridden
0.2.0 #
- separate singleton and transient instantiation use:
Ref.singleton,Ref.transient,Ref.asyncSingletonandRef.asyncTransient - add
assertInstancegetter for synchronous access to a AsyncSingletonRef
0.1.0 #
- prevent race condition when fetching async singleton
- add
assertInstancegetter for synchronous access to a LiteAsyncRef - add
.freeze()method which disables overriding
0.0.2 #
- Update readme
0.0.1 #
- Initial release