context_plus
6.0.7, released 7 months ago by sonerik.dev
Convenient value propagation and reactive observation for Flutter widgets.
WASM-ready
What it does
Combines context_ref and context_watch to let you bind, propagate, and observe reactive values like Streams, Futures, Listenables, and Notifiers directly through the BuildContext with minimal boilerplate.
AI-written summary of version 6.0.7, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to share values down the widget tree without verbose InheritedWidgets.
- You want to easily watch Listenables, Futures, or Streams inside widgets with automatic rebuilding.
- You want a lightweight alternative to heavier state management frameworks.
Skip it when
- You already rely heavily on Riverpod or Bloc for all state management and dependency injection.
- Your project cannot use ContextPlus.root at the root of the application.
Strengths
- Drastically reduces boilerplate for watching streams, futures, and listenables.
- Unifies context_ref and context_watch into a single package.
- Supports multi-value observing via records up to 4 values.
- Automatic cleanup and disposal of bound values tied to BuildContext lifecycle.
Weaknesses
- Requires wrapping your app in ContextPlus.root.
- Relies on custom extension methods on BuildContext and Ref which might have a learning curve for new team members.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
Wrap your root widget in ContextPlus.root(child: MaterialApp(...)) and optionally add the context_plus_lint plugin.
final _stream = Ref<Stream>();
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
final streamSnapshot = _stream.watch(context);
return const Text('Watching stream');
}
}Alternatives
Packages that do the same job and could replace context_plus.
Works with
Packages commonly used together with context_plus: ones it builds on, ones built on it, and its own family.