debugCheckHasOverlay function Null safety

bool debugCheckHasOverlay (
  1. BuildContext context
)

Asserts that the given context has an Overlay ancestor.

To call this function, use the following pattern, typically in the relevant Widget's build method:

assert(debugCheckHasOverlay(context));

Does nothing if asserts are disabled. Always returns true.

Implementation

bool debugCheckHasOverlay(BuildContext context) {
  assert(() {
    if (context.widget is! Overlay && context.findAncestorWidgetOfExactType<Overlay>() == null) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('No Overlay widget found.'),
        ErrorDescription(
          '${context.widget.runtimeType} widgets require an Overlay '
          'widget ancestor.\n'
          'An overlay lets widgets float on top of other widget children.'
        ),
        ErrorHint(
          'To introduce an Overlay widget, you can either directly '
          'include one, or use a widget that contains an Overlay itself, '
          'such as a Navigator, WidgetApp, MaterialApp, or CupertinoApp.',
        ),
        ...context.describeMissingAncestor(expectedAncestorType: Overlay)
      ]
      );
    }
    return true;
  }());
  return true;
}