US Office

1176 Shadeville Rd, Crawfordville Florida 32327, USA

 +1 (850) 780-1313

India Office

Office No 405, Kabir Shilp, Opp. Kansar Hotel, Opp. Landmark, Kudasan, Gandhinagar, Gujarat 382421

[email protected]

How to Programmatically Exit the App In Flutter?

How to Programmatically Exist the App In Flutter

How to Programmatically Exit 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 here about how to Programmatically Exit the App in Flutter.

Learn how to programmatically exit your Flutter app with ease in this informative blog post. Discover the techniques and code snippets that allow you to gracefully terminate your app when certain conditions are met or specific user actions are triggered. Whether you need to implement an exit button, handle back button presses, or add custom logic to exit the app, this tutorial will guide you through the process step-by-step. Gain a comprehensive understanding of how to ensure a smooth and controlled app exit experience for your users. Take control of your Flutter app’s termination process today by mastering the art of programmatically exiting the app.

Know 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 the topic.

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.

Post a Comment