insert method

void insert (
  1. OverlayEntry entry,
  2. {OverlayEntry below,
  3. OverlayEntry above}
)

Insert the given entry into the overlay.

If below is non-null, the entry is inserted just below below. If above is non-null, the entry is inserted just above above. Otherwise, the entry is inserted on top.

It is an error to specify both above and below.

Implementation

void insert(OverlayEntry entry, { OverlayEntry below, OverlayEntry above }) {
  assert(
    above == null || below == null,
    'Only one of `above` and `below` may be specified.',
  );
  assert(
    above == null || (above._overlay == this && _entries.contains(above)),
    'The provided entry for `above` is not present in the Overlay.',
  );
  assert(
    below == null || (below._overlay == this && _entries.contains(below)),
    'The provided entry for `below` is not present in the Overlay.',
  );
  assert(!_entries.contains(entry), 'The specified entry is already present in the Overlay.');
  assert(entry._overlay == null, 'The specified entry is already present in another Overlay.');
  entry._overlay = this;
  setState(() {
    _entries.insert(_insertionIndex(below, above), entry);
  });
}