of static method

NavPagesState of(
  1. BuildContext context
)

Returns the NavPagesState associated with the nearest NavPages widget.

This method is used to access the navigation state from descendant widgets. Throws a FlutterError if no NavPages widget is found in the widget tree.

Example:

final navPages = NavPages.of(context);
navPages.push(AnotherPage());

Implementation

static NavPagesState of(BuildContext context) {
  NavPagesState? state = context.findAncestorStateOfType<NavPagesState>();

  assert(() {
    if (state == null) {
      throw FlutterError('NavPages not found in context');
    }
    return true;
  }());

  return state!;
}