rearrange method

void rearrange(
  1. Iterable<OverlayEntry> newEntries,
  2. {OverlayEntry? below,
  3. OverlayEntry? above}

Remove all the entries listed in the given iterable, then reinsert them into the overlay in the given order.

Entries mention in newEntries but absent from the overlay are inserted as if with insertAll.

Entries not mentioned in newEntries but present in the overlay are positioned as a group in the resulting list relative to the entries that were moved, as specified by one of below or above, which, if specified, must be one of the entries in newEntries:

If below is non-null, the group is positioned just below below. If above is non-null, the group is positioned just above above. Otherwise, the group is left on top, with all the rearranged entries below.

It is an error to specify both above and below.


void rearrange(Iterable<OverlayEntry> newEntries, { OverlayEntry? below, OverlayEntry? above }) {
  final List<OverlayEntry> newEntriesList = newEntries is List<OverlayEntry> ? newEntries : newEntries.toList(growable: false);
  assert(_debugVerifyInsertPosition(above, below, newEntries: newEntriesList));
    newEntriesList.every((OverlayEntry entry) => entry._overlay == null || entry._overlay == this),
    'One or more of the specified entries are already present in another Overlay.',
    newEntriesList.every((OverlayEntry entry) => _entries.indexOf(entry) == _entries.lastIndexOf(entry)),
    'One or more of the specified entries are specified multiple times.',
  if (newEntriesList.isEmpty) {
  if (listEquals(_entries, newEntriesList)) {
  final LinkedHashSet<OverlayEntry> old = LinkedHashSet<OverlayEntry>.of(_entries);
  for (final OverlayEntry entry in newEntriesList) {
    entry._overlay ??= this;
  setState(() {
    _entries.insertAll(_insertionIndex(below, above), old);