패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.1.2

flutter_exit_app

Dart 코드에서 exit(0)을 호출하지 않고 플랫폼별로 앱을 종료할 수 있도록 해주는 Flutter 플러그인입니다.

AndroidiOS
30일 다운로드
2.3만
좋아요
62
Pub 점수
160

패키지 설치

flutter pub add flutter_exit_app

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

플랫폼별 앱 종료를 가능하게 하는 플러터 플러그인으로, 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.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트