flutterdart

Flutter how to programmatically exit the app


How can I programmatically close a Flutter application. I've tried popping the only screen but that results in a black screen.


Solution

  • For iOS

    SystemNavigator.pop(): Does NOT WORK

    exit(0): Works but Apple may SUSPEND YOUR APP

    Please see:
    https://developer.apple.com/library/archive/qa/qa1561/_index.html


    For Android

    SystemNavigator.pop(): Works and is the RECOMMENDED way of exiting the app.

    exit(0): Also works but it's NOT RECOMMENDED as it terminates the Dart VM process immediately and user may think that the app just got crashed.

    Please see:
    https://api.flutter.dev/flutter/services/SystemNavigator/pop.html