Flutter how to programmatically exit the app

1 Min Read

In Flutter, you can programmatically exit the app using the exit function from the dart:io library. You can call this function within a button tap or any other event that you want to use to exit the app.

Here’s an example:

import 'dart:io';


  onPressed: () {
    // Programmatically exit the app
  child: Text('Exit'),

Note that calling exit will terminate the app immediately, so it’s important to use it with caution. In most cases, it’s better to allow the user to navigate back to the previous screen or to the home screen, rather than exiting the app.

Share this Article
Leave a comment