of static method
- BuildContext context
Retrieves the HeroController from the closest HeroControllerScope ancestor.
If no ancestor is found, this method will assert in debug mode, and throw an exception in release mode.
Calling this method will create a dependency on the closest
HeroControllerScope in the context
.
See also:
- HeroControllerScope.maybeOf, which is similar to this method, but returns null if no HeroControllerScope ancestor is found.
Implementation
static HeroController of(BuildContext context) {
final HeroController? controller = maybeOf(context);
assert(() {
if (controller == null) {
throw FlutterError(
'HeroControllerScope.of() was called with a context that does not contain a '
'HeroControllerScope widget.\n'
'No HeroControllerScope widget ancestor could be found starting from the '
'context that was passed to HeroControllerScope.of(). This can happen '
'because you are using a widget that looks for a HeroControllerScope '
'ancestor, but no such ancestor exists.\n'
'The context used was:\n'
' $context',
);
}
return true;
}());
return controller!;
}