activeIdsByStackOrder property

List<String> get activeIdsByStackOrder

Returns active modal IDs sorted by stack level (bottom to top).

Implementation

static List<String> get activeIdsByStackOrder {
  final items = <({String id, int level})>[];

  if (_sheetController.state != null) {
    items.add((
      id: _sheetController.state!.uniqueId,
      level: _sheetController.state!.stackLevel
    ));
  }
  if (_dialogController.state != null) {
    items.add((
      id: _dialogController.state!.uniqueId,
      level: _dialogController.state!.stackLevel
    ));
  }
  for (final queue in _snackbarQueueNotifier.state.values) {
    for (final content in queue) {
      items.add((id: content.uniqueId, level: content.stackLevel));
    }
  }
  if (_activeModalController.state != null) {
    final activeId = _activeModalController.state!.uniqueId;
    final exists = items.any((item) => item.id == activeId);
    if (!exists) {
      items.add(
          (id: activeId, level: _activeModalController.state!.stackLevel));
    }
  }

  items.sort((a, b) {
    final byLevel = a.level.compareTo(b.level);
    if (byLevel != 0) return byLevel;
    return a.id.compareTo(b.id);
  });

  return items.map((e) => e.id).toList();
}