of<T extends Object?> static method

  1. @optionalTypeArgs
TransModalRoute<T>? of<T extends Object?>(
  1. BuildContext context
)

Returns the modal route most closely associated with the given context.

Returns null if the given context is not associated with a modal route.

{@tool snippet}

Typical usage is as follows:

ModalRoute<int>? route = ModalRoute.of<int>(context);

{@end-tool}

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 TransModalRoute<T>? of<T extends Object?>(BuildContext context) {
  final _ModalScopeStatus? widget =
      context.dependOnInheritedWidgetOfExactType<_ModalScopeStatus>();
  return widget?.route as TransModalRoute<T>?;
}