overlay property

OverlayState get overlay

The OverlayState of the tester's wrapping Overlay. Useful for assertions on overlay entry count when a test exercises OverlayEntry.insert directly. Throws when called before the first pumpWidget.

Implementation

OverlayState get overlay {
  final root = _root;
  if (root == null) {
    throw StateError(
      'FleuryTester.overlay accessed before pumpWidget; the tree is empty.',
    );
  }
  OverlayState? found;
  void visit(Element e) {
    if (found != null) return;
    if (e is StatefulElement && e.state is OverlayState) {
      found = e.state as OverlayState;
      return;
    }
    e.visitChildren(visit);
  }

  visit(root);
  if (found == null) {
    throw StateError(
      'FleuryTester.overlay could not locate an OverlayState in the '
      'tree — the wrapper should have installed one.',
    );
  }
  return found!;
}