read<T extends ChangeNotifier> static method

T read<T extends ChangeNotifier>(
  1. BuildContext context, {
  2. String? tag,
})

Accesses the controller without subscribing to changes.

Use this inside event handlers (onPressed, etc.) or callbacks to avoid unnecessary rebuilds. If a tag is provided, it specifically searches for the instance associated with that tag. If no tag is provided, it returns the nearest instance of T found in the widget tree.

Throws a FlutterError if no MinProvider for T is found, or if a specific tag was requested but not found in the ancestor chain.

Implementation

static T read<T extends ChangeNotifier>(BuildContext context, {String? tag}) {
  return _findNotifier<T>(context, tag, false).notifier!;
}