pop method
- Object? result
Plays the running navigation back, or with none running, plays the top
route's push back, uncovering the route beneath and completing that push
with result, which must be of the type it asked for. Completes once the
navigation settles. Throws a StateError on an empty stack.
Implementation
Future<void> pop([Object? result]) {
final navigation = _navigation;
if (navigation != null && navigation.turn()) {
final incoming = navigation.incoming;
incoming._complete(result);
// Taken back before its route reached the tree, so it never happened.
if (!incoming.isMounted) _settle();
return navigation.settled.future;
}
// Settling a running navigation takes what it leaves off the stack, so
// the stack is read after.
_settle();
final stack = routes;
if (stack.isEmpty) throw StateError('Nothing to pop.');
final leaving = stack.last;
leaving._complete(result);
return _launch(
_Layer(
leaving.transition ?? transition,
incoming: leaving,
covered: stack.length > 1 ? stack.elementAt(stack.length - 2) : null,
backdrop: leaving.backdrop,
forward: false,
),
);
}