of static method

Implementation

static NavigationMenuState of(BuildContext context) {
  final NavigationMenuState? result = _state;
  if (result != null) {
    return result;
  }
  throw FlutterError.fromParts(<DiagnosticsNode>[
    ErrorSummary(
      'NavigationMenu.of() called with a context that does not contain a NavigationMenu.',
    ),
    ErrorDescription(
      'No NavigationMenu ancestor could be found starting from the context that was passed to NavigationMenu.of(). '
      'This usually happens when the context provided is from the same StatefulWidget as that '
      'whose build function actually creates the NavigationMenu widget being sought.',
    ),
    ErrorHint(
      'There are several ways to avoid this problem. The simplest is to use a Builder to get a '
      'context that is "under" the NavigationMenu. For an example of this, please see the '
      'documentation for NavigationMenu.of():\n'
      '  https://api.flutter.dev/flutter/material/NavigationMenu/of.html',
    ),
    ErrorHint(
      'A more efficient solution is to split your build function into several widgets. This '
      'introduces a new context from which you can obtain the NavigationMenu. In this solution, '
      'you would have an outer widget that creates the NavigationMenu populated by instances of '
      'your new inner widgets, and then in these inner widgets you would use NavigationMenu.of().\n'
      'A less elegant but more expedient solution is assign a GlobalKey to the NavigationMenu, '
      'then use the key.currentState property to obtain the NavigationMenuState rather than '
      'using the NavigationMenu.of() function.',
    ),
    context.describeElement('The context used was'),
  ]);
}