didPopRoute method

  1. @protected
  2. @override
  3. @mustCallSuper
Future<bool> didPopRoute()
inherited

Called when the system tells the app to pop the current route. For example, on Android, this is called when the user presses the back button. Observers are notified in registration order until one returns true. If none return true, the application quits.

Implementation

@protected
@override
@mustCallSuper
Future<bool> didPopRoute() async {
  /// Observers are expected to return true if they were able to
  /// handle the notification, for example by closing an active dialog
  /// box, and false otherwise. The [WidgetsApp] widget uses this
  /// mechanism to notify the [Navigator] widget that it should pop
  /// its current route if possible.
  ///
  /// This method exposes the `popRoute` notification from
  /// [SystemChannels.navigation].
  ///
  /// No 'setState()' functions are allowed to fully function at this point.
  _rebuildAllowed = false;

  /// Set if a Controller successfully 'handles' the notification.
  bool handled = false;

  for (final listener in _beforeList) {
    await listener.didPopRoute();
  }
  for (final con in _controllerList) {
    final didPop = await con.didPopRoute();
    if (didPop) {
      handled = true;
    }
  }
  for (final listener in _afterList) {
    await listener.didPopRoute();
  }
  _rebuildAllowed = true;
  if (_rebuildRequested || _inTester) {
    _rebuildRequested = false;

    /// Perform a 'rebuild' if requested.
    refresh();
  }
  // Return false to pop out
  return handled;
}