context_plus 2.2.2 copy "context_plus: ^2.2.2" to clipboard
context_plus: ^2.2.2 copied to clipboard

Convenient value propagation and observing for Flutter

context_plus #

context_plus.png

context_plus context_plus context_plus 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. Calling Ref.of(context), Ref.watch(context), Ref.watchOnly(context, ...) via this package will invoke context.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.