didRequestAppExit method
Called when a request is received from the system to exit the application.
Implementation
@override
@mustCallSuper
Future<AppExitResponse> didRequestAppExit() async {
/// Exiting the application can proceed.
var appResponse = AppExitResponse.exit;
// A triggered system event
_hadSystemEvent = true;
// Don't if the State object is defunct.
if (!mounted) {
return appResponse;
}
/// No 'setState()' functions are allowed to fully function at this point.
_setStateAllowed = false;
// 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 (isLastState) {
/// Perform a 'rebuild' if requested.
setState(() {});
}
}
return appResponse;
}