use<T extends ChangeNotifier> static method
Retrieves a specific controller of type T
from the nearest MinMultiProvider ancestor in the widget tree.
Throws a FlutterError if no MinMultiProvider is found in the widget tree or if the controller of type T
is not found within it.
Example usage:
final controller = MinMultiProvider.use<MyController>(context);
Implementation
static T use<T extends ChangeNotifier>(BuildContext context) {
final provider = maybeOf(context);
if (provider == null) {
throw FlutterError(
'MinMultiProvider was not found in the widget tree.\n'
'Make sure MinMultiProvider is above the widget that '
'is trying to access it.',
);
}
final controller = provider.controllers.firstWhere(
(c) => c is T,
orElse: () => throw FlutterError(
'Controller of type $T not found in MinMultiProvider.\n'
'Make sure the controller is added to the MinMultiProvider.',
),
);
return controller as T;
}