简体   繁体   中英

Flutter - programmatically close application when init failed

My app performs some checks inside main() function, before runApp( MyApp()); , most important is load app configuration from Firebase. If failed, there's no any way to run not configured app. So I want to show message box saying "app configuration load failed", then after user press OK, exit app.

What is preferred way to exit app in that case? I need it working on iOS and Android.

If you need UI, I would suggest still calling runApp but on a different widget:

if(success){
    runApp(MyApp());
} else {
   runApp(ErrorApp());
}

For closing a flutter app programmatically, the best way is using SystemNavigator.pop() but if that didn't work, you can try exit(0) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM