Skip to content
pubscout

context_watch

7.0.3, released a year ago by sonerik.dev

Observe value changes within the build method using extensions.

WASM-ready
$ flutter pub add context_watch
Source repository

What it does

Provides extension methods like watch(), watchOnly(), and watchEffect() on observable types such as Listenable, ValueListenable, Stream, and Future. It allows widgets to automatically rebuild or execute side effects when observables notify of changes without using builders or custom base classes.

AI-written summary of version 7.0.3, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to observe ValueListenables, Streams, or Futures directly inside the build method.
  • You want to avoid boilerplate code like ValueListenableBuilder or StreamBuilder.

Skip it when

  • You prefer an explicit architecture pattern like BLoC or Riverpod for large state management.
  • You cannot wrap your app in the required ContextWatch.root widget.

Strengths

  • No builders or custom base classes required.
  • Supports conditional watching automatically.
  • Provides synchronous initial values for async types without skipped frames.

Weaknesses

  • Requires wrapping the app in a root widget.
  • Relies heavily on extensions on BuildContext.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
3

Wrap your app in a ContextWatch.root widget.

ContextWatch.root(
  child: MaterialApp(
    home: Scaffold(
      body: Builder(
        builder: (context) {
          final counter = counterNotifier.watch(context);
          return Text('Counter: $counter');
        },
      ),
    ),
  ),
);

Alternatives

Packages that do the same job and could replace context_watch.

  • provider

    Provides a traditional InheritedWidget-based dependency and state management approach.

  • flutter_riverpod

    Offers compile-time safe, robust global state management without needing a BuildContext for reading.

  • flutter_bloc

    Uses streams and explicit events/states for structured, predictable state management.

Works with

Packages commonly used together with context_watch: ones it builds on, ones built on it, and its own family.