didRequestAppExit method

  1. @protected
  2. @override
  3. @mustCallSuper
Future<AppExitResponse> didRequestAppExit()
inherited

Called when a request is received from the system to exit the application.

Implementation

@protected
@override
@mustCallSuper
Future<AppExitResponse> didRequestAppExit() async {
  // A triggered system event
  _hadSystemEvent = true;

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

  /// Exiting the application can proceed.
  var appResponse = AppExitResponse.exit;

  // All must allow an exit or it's cancelled.
  for (final con in _controllerList) {
    //
    final response = await con.didRequestAppExit();

    /// Cancel and do not exit the application.
    if (response == AppExitResponse.cancel) {
      // Record the 'cancel' response
      appResponse = response;
    }
  }

  _setStateAllowed = true;

  // If staying with the app and a setState() was requested.
  if (_setStateRequested && appResponse == AppExitResponse.cancel) {
    _setStateRequested = false;
    // Only the latest State is rebuilt
    if (isEndState) {
      /// Perform a 'rebuild' if requested.
      setState(() {});
    }
  }

  return appResponse;
}