use<T extends ChangeNotifier> static method
Retrieves the controller of type T
from the nearest MinProvider ancestor in the widget tree.
Throws a FlutterError if no MinProvider of type T
is found in the widget tree.
Example usage:
final controller = MinProvider.read<MyController>(context);
This method ensures that the widget attempting to access the controller has a corresponding MinProvider above it in the widget hierarchy.
Implementation
static T use<T extends ChangeNotifier>(BuildContext context) {
final provider = maybeOf<T>(context);
if (provider == null) {
throw FlutterError(
'MinProvider<$T> was not found in the widget tree.\n'
'Make sure MinProvider<$T> is above the widget that '
'is trying to access it.',
);
}
return provider.controller;
}