context_plus
This package combines context_ref and context_watch into a single, more convenient package.
Features
- Makes observing a value from
Ref
more 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<Listenable> , Ref<Stream> , Ref<Future> |
ref.watch(context) |
context.unwatch(); |
Ref<Listenable> , Ref<Stream> , Ref<Future> |
ref.watchOnly(context, ...) |
context.unwatch(); |
Ref<ValueListenable> |
ref.watchValue(context) |
context.unwatch(); |
Ref<ValueListenable> |
ref.watchValueOnly(context, ...) |
context.unwatch(); |
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.