How to Programmatically Exist the App In Flutter ?

· 2 min read
How to Programmatically Exist the App In Flutter
How to Programmatically Exist the App In Flutter

Generally, while designing and developing mobile Applications Sometimes users may require to exist the app So in this article, we will learn about How to Programmatically Exist the App In Flutter?

How to Programmatically Exist the App In Flutter?

Depending on the type of platform the user is working with kindly follow the below instruction.

For iOS

SystemNavigator.pop(): Does NOT WORK

exit(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 the user may think that the app just got crashed.

Below worked perfectly with me in both Android and iOS, I used exit(0) from dart:io.

import 'dart:io';

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new ... (...),
          floatingActionButton: new FloatingActionButton(
            onPressed: ()=> exit(0),
            tooltip: 'Close app',
            child: new Icon(Icons.close),
          ), 
    );
  }

Users can also try the below things:

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

Conclusion:

In this article, we have been through How to Programmatically Exist the App In Flutter?

Still, need support for Flutter? We are always there to serve you better.

Keep Fluttering !!!
Keep Learning !!!

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply