of static method

OverlayState of(
  1. BuildContext context
)

Returns the OverlayState of the nearest ancestor Overlay. Throws if none exists (a missing overlay almost always means runApp wasn't used or the call site is outside the app's root).

Implementation

static OverlayState of(BuildContext context) {
  final state = context.findAncestorStateOfType<OverlayState>();
  if (state == null) {
    throw StateError(
      'No Overlay above this BuildContext. Make sure you started the '
      'app with runApp() (which installs a root Overlay), or wrap '
      'your widget tree manually in Overlay(initialEntries: [...]).',
    );
  }
  return state;
}