of<T extends Object?> method
Null safety
- BuildContext context
optionalTypeArgs">@optionalTypeArgs
Returns the modal route most closely associated with the given context.
Returns null if the given context is not associated with a modal route.
Typical usage is as follows:
ModalRoute<int>? route = ModalRoute.of<int>(context);
The given BuildContext will be rebuilt if the state of the route changes while it is visible (specifically, if isCurrent or canPop change value).
Implementation
@optionalTypeArgs
static ModalRoute<T>? of<T extends Object?>(BuildContext context) {
final _ModalScopeStatus? widget = context.dependOnInheritedWidgetOfExactType<_ModalScopeStatus>();
return widget?.route as ModalRoute<T>?;
}