popUntil method

  1. @override
void popUntil(
  1. Key key
)
override

Removes widgets from the stack until the given type of widget is found.

Implementation

@override
void popUntil(Key key) {
  if (_stack.isEmpty) {
    throw Exception('The stack is empty. No widget to pop.');
  } else {
    onRenderScreen.value = false;
    while (_stack.isNotEmpty && _stack.last.key != key) {
      _stack.removeLast();
    }
    notifyListeners();

    // Check if the stack is empty or the widget type not found
    if (_stack.isEmpty) {
      throw Exception('No widget of specified type found.');
    }
  }
}