How can I programmatically close a Flutter application. I've tried popping the only screen but that results in a black screen.
相关问题
- What means in Dart static type and why it differs
- Flutter : Prepare list data from http request
- How to schedule an alarm on specific time in Flutt
- MappedListIterable is not a SubType
- 'firebase_messaging/FirebaseMessagingPlugin.h&
相关文章
- Observatory server failed to start - Fails to crea
- Flutter error retrieving device properties for ro.
- Adding Shadows at the bottom of a container in flu
- Flutter. Check if a file exists before loading it
- Flutter - http.get fails on macos build target: Co
- Receive share file intents with Flutter
- Do stateless widgets dispose on their own?
- How to clean your build with Flutter RP2 in Androi
For iOS
SystemNavigator.pop()
: Does NOT WORKexit(0)
: Works but Apple may SUSPEND YOUR APP because it's against Apple Human Interface guidelines to exit the app programmatically.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.Answers are provided already but please don't just copy paste those into your code base without knowing what you are doing:
If you use
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
note that doc is clearly mentioning:You can use
exit(0)
. And that will terminate the Dart VM process immediately with the given exit code. But remember that doc says:Anyway the doc also did note
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
:So, keep remember what you are doing.
You can do this with
SystemNavigator.pop()
.Below worked perfectly with me in both
Android
andiOS
, I usedexit(0)
fromdart:io
UPDATE Jan 2019 Preferable solution is:
As described here