useRouteState<T> function

T? useRouteState<T>(
  1. BuildContext context
)

Returns typed navigation state from the nearest route scope.

Implementation

T? useRouteState<T>(BuildContext context) {
  final location = RouteScopeProvider.of(context).location;
  return switch (location.state) {
    T state => state,
    null => null,
    final other => throw StateError(
      'Unrouter state is of unexpected type: '
      'expected $T but got ${other.runtimeType}.',
    ),
  };
}