find<T extends Intent> static method
- BuildContext context, {
- T? intent,
Finds the Action bound to the given intent type T
in the given context
.
Creates a dependency on the Actions widget that maps the bound action so that if the actions change, the context will be rebuilt and find the updated action.
The optional intent
argument supplies the type of the intent to look for
if the concrete type of the intent sought isn't available. If not
supplied, then T
is used.
If no Actions widget surrounds the given context, this function will assert in debug mode, and throw an exception in release mode.
See also:
Implementation
static Action<T> find<T extends Intent>(BuildContext context, { T? intent }) {
final Action<T>? action = maybeFind(context, intent: intent);
assert(() {
if (action == null) {
final Type type = intent?.runtimeType ?? T;
throw FlutterError(
'Unable to find an action for a $type in an $Actions widget '
'in the given context.\n'
"$Actions.find() was called on a context that doesn't contain an "
'$Actions widget with a mapping for the given intent type.\n'
'The context used was:\n'
' $context\n'
'The intent type requested was:\n'
' $type',
);
}
return true;
}());
return action!;
}