maybeOf static method

GoRouter? maybeOf(
  1. BuildContext context
)

The current GoRouter in the widget tree, if any.

Implementation

static GoRouter? maybeOf(BuildContext context) {
  final inherited =
      context
              .getElementForInheritedWidgetOfExactType<InheritedGoRouter>()
              ?.widget
          as InheritedGoRouter?;
  if (inherited != null) {
    return inherited.goRouter;
  }

  // Check if we're in a redirect context
  return Zone.current[currentRouterKey] as GoRouter?;
}