パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.1.2

flutter_exit_app

Dartコードでexit(0)を呼び出さずに、プラットフォーム固有の方法でアプリを終了するためのFlutterプラグインです。

AndroidiOS
30日間ダウンロード
2.3万
いいね数
62
Pub ポイント
160

パッケージをインストール

flutter pub add flutter_exit_app

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

プラットフォーム固有のアプリ終了を可能にするFlutterプラグインで、Dartのexit(0)を使用せずにユーザーがアプリをスムーズに終了できるようにします。AndroidおよびiOSでの互換性と適切な動作を保証するために、ネイティブプラットフォームメソッドを利用しています。このプラグインは、戻るボタンを押す、またはメニューから「終了」を選択するなどのユーザー操作に応じてアプリをクリーンに閉じたい開発者向けに設計されています。プロセスの直接終了を回避し、より良いアプリライフサイクル管理を促進します。

用途

  • 戻るキーでアプリを終了する
  • 終了確認ダイアログの実装
  • 設定メニューからアプリを終了する
  • キオスクモードでのスムーズなシャットダウン
  • フルスクリーンアプリでのアプリ終了処理

主な機能

  • プラットフォーム固有の終了動作
  • exit(0) を呼び出す必要はありません
  • Android および iOS をサポート
  • シンプルな API インテグレーション
  • アプリのライフサイクルを尊重する

適している対象

  • キオスクまたはフルスクリーンアプリを開発する開発者
  • 終了前にユーザーの確認が必要なアプリ
  • ネイティブな終了動作を必要とするプロジェクト
  • カスタムナビゲーションフローを持つモバイルアプリ
  • Android および iOS の両方をターゲットにするアプリ

注意事項

  • 一部のプラットフォームではデバッグモードで動作しません
  • バックグラウンドタスクの処理に追加の処理が必要になる場合があります
  • テストで exit(0) に依存するアプリには適していません
  • 終了タイミングに対する制御が限定的
  • Android では適切な権限処理が必要です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト