NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
pub.dev · #3801 most downloaded on pub.dev
A lightweight dependency injection package with support for overriding for testing.
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
[Fix] Fixed bug with disposal of widget state.
[Fix] Fixed bug with hot-reloading
[Fix] Fixed bug with hot-reloading
[Feat] Add Ref.scopedFamily which 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) or postController(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...');
},
);
}
}
One column per month.
Add ScopedRef.read(context) by @JinyuS in #19
Full Changelog: v0.6.1...v0.7.0
[Fix] Fixed bug where refs were disposed when the child is temporarily deactivated.
[Breaking] The overrides property of LiteRefScope is now a Set of ScopedRefs instead of a List of ScopedRefs.
LiteRefScope(
overrides: [
settingsServiceRef.overrideWith((ctx) => MockSettingsService()),
]
child: MyApp(),
)
LiteRefScope(
overrides: {
settingsServiceRef.overrideWith((ctx) => MockSettingsService()),
}
child: MyApp(),
)
- [Refactor] minor refactor
[Feat] Add onlyOverrides to LiteRefScope which will only provide overridden instances to children.
onlyOverrides to LiteRefScope which will only provide overridden instances to children.Add exists() method to ScopedRef with tests by @JinyuS in #16
Full Changelog: v0.4.0...v0.6.1
ScopedRef.exists(context) method to check if a ScopedRef is initialized in the current LiteRefScope.Update flutter dependency constraint
[Refactor] Add core package as a dependency.
[Fix] Remove dispose function when overriding with autoDispose set to false.
dispose function when overriding with autoDispose set to false.[Feat] Add autodipose for ChangeNotifiers and any class that implements Disposable. These classes will be disposed when all the widgets that have acce
[Feat] Add autodipose for ChangeNotifiers and any class that implements Disposable. 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 set autoDispose to false.
In the example below, the CounterController will be disposed when the CounterView is 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}');
},
);
}
}
[Docs] Add documentation comments and examples
Convert to Flutter package and add Ref.scoped by @JinyuS in #6
Full Changelog: https://github.com/jinyus/lite_ref/commits/v0.4.0
[Breaking] This now a flutter package
Add ScopedRef which is a ref that needs a context to access its instance
Add LiteRefScope which coupled withScopedRef is an alternative to Provider for 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) or settingsServiceRef(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 to settingsServiceRef.of(context) will return MockSettingsService.
LiteRefScope(
overrides: [
settingsServiceRef.overrideWith((ctx) => MockSettingsService()),
]
child: MyApp(),
),
Make the factory function non-nullable (improves performance and maintainability)
Internal performance improvements
separate singleton and transient instantiation use: Ref.singleton, Ref.transient, Ref.asyncSingleton and Ref.asyncTransient
Ref.singleton, Ref.transient, Ref.asyncSingleton and Ref.asyncTransientassertInstance getter for synchronous access to a AsyncSingletonRefprevent race condition when fetching async singleton
assertInstance getter for synchronous access to a LiteAsyncRef.freeze() method which disables overriding- Update readme
- Initial release
Your coding agent can read these notes before it upgrades. Set up the MCP server →