maybePop<T extends Object> method

  1. @optionalTypeArgs
Future<bool> maybePop <T extends Object>(
  1. BuildContext context,
  2. [T result]

Tries to pop the current route of the navigator that most tightly encloses the given context, while honoring the route's Route.willPop state.

Returns false if the route deferred to the next enclosing navigator (possibly the system); otherwise, returns true (whether the route was popped or not).

This method is typically called to handle a user-initiated pop. For example on Android it's called by the binding for the system's back button.

The T type argument is the type of the return value of the current route. See also:

  • Form, which provides an onWillPop callback that enables the form to veto a pop initiated by the app's back button.
  • ModalRoute, which provides a scopedWillPopCallback that can be used to define the route's willPop method.


static Future<bool> maybePop<T extends Object>(BuildContext context, [ T result ]) {
  return Navigator.of(context).maybePop<T>(result);