context_plus 2.2.2
context_plus: ^2.2.2 copied to clipboard
Convenient value propagation and observing for Flutter
context_plus #

This package combines context_ref and context_watch into a single, more convenient package.
Features #
- Makes observing a value from
Refmore convenient. - Reduces the likeliness of extra rebuilds due to conditional
watch()calls. CallingRef.of(context),Ref.watch(context),Ref.watchOnly(context, ...)via this package will invokecontext.unwatch()under the hood.
| Types | context_plus | context_watch + context_ref (separately) |
|---|---|---|
Ref<T> |
ref.of(context) |
context.unwatch(); ref.of(context); |
Ref<T> |
ref.bind(context, ...) |
context.unwatch(); ref.bind(context); |
Ref<T> |
ref.bindLazy(context, ...) |
context.unwatch(); ref.bindLazy(context); |
Ref<T> |
ref.bindValue(context, ...) |
context.unwatch(); ref.bindValue(context); |
Ref<Listenable>, Ref<Stream>, Ref<Future> |
ref.watch(context) |
context.unwatch(); ref.of(context).watch(context); |
Ref<Listenable>, Ref<Stream>, Ref<Future> |
ref.watchOnly(context, ...) |
context.unwatch(); ref.of(context).watchOnly(context, ...); |
Getting started #
Add context_plus to your pubspec.yaml:
flutter pub add context_plus
Remove context_ref and context_watch from your pubspec.yaml if you have them:
flutter pub remove context_ref
flutter pub remove context_watch
Wrap your app in ContextPlus.root. Remove ContextWatch.root and ContextRef.root if you have them.
ContextPlus.root(
child: MaterialApp(...),
);
(Optional) Wrap default error handlers with ContextPlus.errorWidgetBuilder() and ContextPlus.onError() to get better hot reload related error messages. Replace ContextRef.errorWidgetBuilder() and ContextRef.onError() if you have them.
void main() {
ErrorWidget.builder = ContextPlus.errorWidgetBuilder(ErrorWidget.builder);
FlutterError.onError = ContextPlus.onError(FlutterError.onError);
}
Usage #
See context_ref and context_watch for more information.