Search packages, repositories and app categories

Package detailsv2.1.2

flutter_exit_app

A Flutter plugin that provides a platform-specific way to exit the app without calling exit(0) in Dart code.

AndroidiOS
30-day downloads
22.8K
Likes
62
Pub points
160

Install package

flutter pub add flutter_exit_app

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter plugin that enables platform-specific app termination, allowing users to exit the app gracefully without using Dart's exit(0). It leverages native platform methods to ensure compatibility and proper behavior across Android and iOS. The plugin is designed for developers seeking a clean way to close the app in response to user actions, such as pressing a back button or selecting 'Exit' from a menu. It avoids direct process termination, promoting better app lifecycle management.

Use cases

  • Exiting the app on back press
  • Implementing an exit confirmation dialog
  • Closing the app from a settings menu
  • Graceful shutdown in kiosk mode
  • Handling app exit in full-screen apps

Key features

  • Platform-specific exit behavior
  • No need to call exit(0)
  • Supports Android and iOS
  • Simple API integration
  • Respects app lifecycle

Suitable for

  • Developers building kiosk or fullscreen apps
  • Apps requiring user confirmation before exit
  • Projects needing native exit behavior
  • Mobile apps with custom navigation flows
  • Apps targeting both Android and iOS

Considerations

  • Does not work in debug mode on some platforms
  • May require additional handling for background tasks
  • Not suitable for apps relying on exit(0) for testing
  • Limited control over exit timing
  • Requires proper permission handling on Android

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

flutter_exit_app

A Flutter plugin that provides a platform-specific way to exit your application without calling exit(0) in Dart code.

Features

  • Android: Cleanly finishes the activity and removes it from the task list
  • iOS: Suspends the application (Apple guideline compliant) with optional force-exit
  • Modern implementation: Written in Kotlin (Android) and Swift (iOS)
  • Type-safe: Full null-safety support
  • Well-tested: Comprehensive unit tests

Platform Support

Platform Minimum Version
Android API 21 (Android 5.0)
iOS 12.0

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_exit_app: ^2.1.1

Then run:

flutter pub get

Usage

Import the package
import 'package:flutter_exit_app/flutter_exit_app.dart';
Basic exit (recommended)
// Exit the app using platform-specific methods
// iOS: Suspends the app (Apple guideline compliant)
// Android: Finishes activity and exits
await FlutterExitApp.exitApp();
Force exit on iOS (not recommended)
// Force-kill the iOS app process (against Apple guidelines)
// Only use when absolutely necessary
await FlutterExitApp.exitApp(iosForceExit: true);
Complete example
import 'package:flutter/material.dart';
import 'package:flutter_exit_app/flutter_exit_app.dart';

class ExitButton extends StatelessWidget {
  const ExitButton({super.key});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: () async {
        // Show confirmation dialog
        final shouldExit = await showDialog<bool>(
          context: context,
          builder: (context) => AlertDialog(
            title: const Text('Exit App'),
            content: const Text('Are you sure you want to exit?'),
            actions: [
              TextButton(
                onPressed: () => Navigator.pop(context, false),
                child: const Text('Cancel'),
              ),
              TextButton(
                onPressed: () => Navigator.pop(context, true),
                child: const Text('Exit'),
              ),
            ],
          ),
        );

        if (shouldExit == true) {
          await FlutterExitApp.exitApp();
        }
      },
      child: const Text('Exit App'),
    );
  }
}

Important Notes

iOS Guidelines

Apple's Human Interface Guidelines discourage apps from programmatically exiting. The plugin provides two modes:

Default mode (iosForceExit: false):

  • Animates the app to background with a smooth fade-out effect
  • Suspends the app gracefully
  • App remains in memory until iOS decides to terminate it
  • Recommended: This is the Apple-approved approach

Force exit mode (iosForceExit: true):

  • Animates the app with fade-out and scale-down effect
  • Forcibly terminates the process after animation
  • Warning: The app will appear to "crash" to users
  • May be rejected during App Store review
  • Only use if you have a specific requirement (e.g., enterprise apps)
Android Behavior

On Android, the plugin finishes the current activity and removes it from the recent tasks list, then exits the process after a 1-second delay to ensure clean shutdown. The app is completely removed from the task manager.

License

See the LICENSE file for details.

Categories

Source repository

Projects using this package