of<T> static method
Get the nearest ancestor ImplicitNavigatorState in the widget tree.
Implementation
static ImplicitNavigatorState<T> of<T>(
BuildContext context, {
bool root = false,
}) {
ImplicitNavigatorState<T>? navigator;
if (context is StatefulElement &&
context.state is ImplicitNavigatorState<T>) {
navigator = context.state as ImplicitNavigatorState<T>;
}
if (root) {
navigator =
context.findRootAncestorStateOfType<ImplicitNavigatorState<T>>() ??
navigator;
} else {
navigator ??=
context.findAncestorStateOfType<ImplicitNavigatorState<T>>();
}
return navigator!;
}