overlayEntry property

OverlayEntry? overlayEntry

The magnifier's OverlayEntry, if currently in the overlay.

This is public in case other overlay entries need to be positioned above or below this overlayEntry. Anything in the paint order after the RawMagnifier will not be displayed in the magnifier; this means that if it is desired for an overlay entry to be displayed in the magnifier, it must be positioned below the magnifier.

link
void magnifierShowExample(BuildContext context) {
  final MagnifierController myMagnifierController = MagnifierController();

  // Placed below the magnifier, so it will show.
  Overlay.of(context).insert(OverlayEntry(
      builder: (BuildContext context) => const Text('I WILL display in the magnifier')));

  // Will display in the magnifier, since this entry was passed to show.
  final OverlayEntry displayInMagnifier = OverlayEntry(
      builder: (BuildContext context) =>
          const Text('I WILL display in the magnifier'));

  Overlay.of(context)
      .insert(displayInMagnifier);
  myMagnifierController.show(
      context: context,
      below: displayInMagnifier,
      builder: (BuildContext context) => const RawMagnifier(
            size: Size(100, 100),
          ));

  // By default, new entries will be placed over the top entry.
  Overlay.of(context).insert(OverlayEntry(
      builder: (BuildContext context) => const Text('I WILL NOT display in the magnifier')));

  Overlay.of(context).insert(
      below:
          myMagnifierController.overlayEntry, // Explicitly placed below the magnifier.
      OverlayEntry(
          builder: (BuildContext context) => const Text('I WILL display in the magnifier')));
}

A null check on overlayEntry will not suffice to check if a magnifier is in the overlay or not; instead, you should check shown. This is because it is possible, such as in cases where hide was called with removeFromOverlay false, that the magnifier is not shown, but the entry is not null.

Implementation

OverlayEntry? get overlayEntry => _overlayEntry;