removeMultiplePops static method

void removeMultiplePops(
  1. List<String> ids
)

Batch removal of multiple overlays for better performance

Implementation

static void removeMultiplePops(List<String> ids) {
  if (ids.isEmpty) return;

  _controller.update<List<PopOverlayContent>>((state) {
    // Find overlays to remove and clean them up
    final toRemove = <PopOverlayContent>[];
    for (final element in state) {
      if (ids.contains(element.id)) {
        element.onDismissed?.call();
        element.dispose();
        toRemove.add(element);
      }
    }

    // Remove all at once for better performance
    for (final element in toRemove) {
      state.remove(element);
    }

    // Re-sort the remaining overlays
    PopOverlay._sortPopList(state);
    return state;
  });

  // Remove these overlays from the invisible list as well
  _invisibleController.update<List<String>>((state) {
    for (final id in ids) {
      state.remove(id);
    }
    return state;
  });
}