didRequestAppExit method

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

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

Implementation

@override
@mustCallSuper
Future<AppExitResponse> didRequestAppExit() async {
  //
  var appResponse = await super.didRequestAppExit();
  //
  if (appResponse == AppExitResponse.exit) {
    //
    final list = statesList(reversed: true, remove: this);
    // Loop through all the StateX objects
    for (final StateX state in list) {
      //
      try {
        //
        if (state.mounted && !state.deactivated) {
          //
          final response = await state.didRequestAppExit();

          if (response == AppExitResponse.cancel) {
            // Cancel and do not exit the application.
            appResponse == response;
            break;
          }
        }
      } catch (e, stack) {
        // Record the error
        recordException(e, stack);
      }
    }
  }
  return appResponse;
}