getStackLevel static method

int? getStackLevel(
  1. String id
)

Gets the current stack level for an active modal/snackbar by ID.

Returns null if not found.

Implementation

static int? getStackLevel(String id) {
  final dialog = _dialogController.state;
  if (dialog != null && (dialog.id == id || dialog.uniqueId == id)) {
    return dialog.stackLevel;
  }

  final sheet = _sheetController.state;
  if (sheet != null && (sheet.id == id || sheet.uniqueId == id)) {
    return sheet.stackLevel;
  }

  final snackbar = _snackbarController.state;
  if (snackbar != null && (snackbar.id == id || snackbar.uniqueId == id)) {
    return snackbar.stackLevel;
  }

  for (final queue in _snackbarQueueNotifier.state.values) {
    for (final content in queue) {
      if (content.id == id || content.uniqueId == id) {
        return content.stackLevel;
      }
    }
  }

  final active = _activeModalController.state;
  if (active != null && (active.id == id || active.uniqueId == id)) {
    return active.stackLevel;
  }
  return null;
}