isModalActiveById static method

bool isModalActiveById(
  1. String id
)

Checks if a modal with the given ID exists and is active

Searches the active modal and snackbar queue for a matching ID. Returns true if found, false otherwise.

Example:

if (Modal.isModalActive('notification_123')) {
  // Don't show duplicate notification
  return;
}
Modal.showSnackbar(text: 'Hello', id: 'notification_123');

Implementation

static bool isModalActiveById(String id) {
  // Check active modal
  if (_activeModalController.state != null) {
    final activeModal = _activeModalController.state!;
    if (activeModal.id == id || activeModal.uniqueId == id) {
      return true;
    }
  }

  // Check snackbar queue
  final queueMap = _snackbarQueueNotifier.state;
  for (final queue in queueMap.values) {
    for (final snackbar in queue) {
      if (snackbar.id == id || snackbar.uniqueId == id) {
        return true;
      }
    }
  }

  return false;
}