didPopRoute method

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

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.
  _setStateAllowed = false;

  /// Set if a StateXController 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();
  }

  _setStateAllowed = true;

  if (_setStateRequested) {
    _setStateRequested = false;
    // Only the latest State is rebuilt
    if (isEndState) {
      /// Perform a 'rebuild' if requested.
      setState(() {});
    }
  }

  // Return false to pop out
  return handled;
}