exitApplication method

  1. @override
Future<AppExitResponse> exitApplication(
  1. AppExitType exitType, [
  2. int exitCode = 0
])
override

Exits the application by calling the native application API method for exiting an application cleanly.

This differs from calling dart:io's exit function in that it gives the engine a chance to clean up resources so that it doesn't crash on exit, so calling this is always preferred over calling exit. It also optionally gives handlers of handleRequestAppExit a chance to cancel the application exit.

The exitType indicates what kind of exit to perform. For ui.AppExitType.cancelable exits, the application is queried through a call to handleRequestAppExit, where the application can optionally cancel the request for exit. If the exitType is ui.AppExitType.required, then the application exits immediately without querying the application.

For ui.AppExitType.cancelable exits, the returned response value is the response obtained from the application as to whether the exit was canceled or not. Practically, the response will never be ui.AppExitResponse.exit, since the application will have already exited by the time the result would have been received.

The optional exitCode argument will be used as the application exit code on platforms where an exit code is supported. On other platforms it may be ignored. It defaults to zero.

See also:

Implementation

@override
Future<ui.AppExitResponse> exitApplication(ui.AppExitType exitType, [int exitCode = 0]) async {
  switch (exitType) {
    case ui.AppExitType.cancelable:
      // The test framework shouldn't actually exit when requested.
      return ui.AppExitResponse.cancel;
    case ui.AppExitType.required:
      throw FlutterError('Unexpected application exit request while running test');
  }
}