present<T> method
Presents a screen and awaits the result it returns via
Navigator.pop(context, result).
Navigates with action and awaits its dismissed future, cast to
T?. Resolves with null on a programmatic dismiss (e.g. a Dismiss
action) or when the screen pops without a result. Declare T to match
the type your screen pops with; a mismatch throws at await time.
Requires action.animated (the default); a non-animated presentation
does not wire a result.
Implementation
Future<T?> present<T>(Present action) {
final didNavigate = navigate(action);
// If the presentation was blocked (navigation callback, blocked dismiss),
// no route is pushed and `Present.dismissed` would never complete. Resolve
// with `null` immediately instead of awaiting a future that hangs.
if (!didNavigate) {
return Future<T?>.value();
}
return action.dismissed.then((result) => result as T?);
}