didPopRoute method

  1. @override
  2. @protected
  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

@override
@protected
@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].

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

  // Don't if the State object is defunct.
  if (!mounted) {
    return handled;
  }

  /// No 'setState()' functions are allowed to fully function at this point.
  _setStateAllowed = false;

  for (final con in controllerList) {
    final didPop = await con.didPopRoute();
    if (didPop) {
      handled = true;
    }
  }

  _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;
}