willPop method

  1. @override
Future<RoutePopDisposition> willPop ()
override

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.

Implementation

@override
Future<RoutePopDisposition> willPop() async {
  if (willHandlePopInternally)
    return RoutePopDisposition.pop;
  return await super.willPop();
}