Flutter how to programmatically exit the app

后端 未结 7 1323
死守一世寂寞
死守一世寂寞 2020-11-27 03:28

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

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 03:40

    I prefer using

     Future.delayed(const Duration(milliseconds: 1000), () {
            SystemChannels.platform.invokeMethod('SystemNavigator.pop');
          });
    

    Although, exit(0) also works but the app closes abruptly and doesn't look nice, kind of seems that the app has crashed.

     Future.delayed(const Duration(milliseconds: 1000), () {
           exit(0);
          });
    

提交回复
热议问题