close<T extends Object?> method

void close<T extends Object?>([
  1. T? result
])

Clears all the sheets from the navigation stack. Topmost widget is closed with animation and its result is returned.

Implementation

void close<T extends Object?>([T? result]) async {
  if (_blockGestures) return;

  if (_sheetEntries.isEmpty) {
    throw StateError('No active sheets to close.');
  }

  // Find the first completer in the navigation stack
  // and use it to return result all the way back.
  final firstCompleter = _sheetEntries.first.completer;

  for (final entry in _sheetEntries.reversed.toList()) {
    if (_sheetEntries.last != entry) {
      _removeSheetSilently(entry);
    }
  }

  _notifyStateChange();
  await Future.delayed(const Duration(milliseconds: 17));
  _pop<T>(result, firstCompleter);
}