willPop method

Future<RoutePopDisposition> willPop ()

Returns false if this route wants to veto a Navigator.pop. This method is called by Navigator.maybePop.

By default, routes veto a pop if they're the first route in the history (i.e., if isFirst). This behavior prevents the user from popping the first route off the history and being stranded at a blank screen.

See also:

  • Form, which provides a Form.onWillPop callback that uses this mechanism.
  • WillPopScope, another widget that provides a way to intercept the back button.


Future<RoutePopDisposition> willPop() async {
  return isFirst ? RoutePopDisposition.bubble : RoutePopDisposition.pop;