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

flutter_window_close 표지
패키지 상세v1.3.0

flutter_window_close

Flutter 앱이 사용자가 앱을 닫기를 원하는지 확인할 수 있도록 하세요.

WebmacOSWindowsLinux
30일 다운로드
3만
좋아요
99
Pub 점수
160

패키지 설치

flutter pub add flutter_window_close

패키지 개요

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

flutter_window_close 패키지는 데스크톱 플랫폼에서 Flutter 애플리케이션의 창 닫기 이벤트를 가로채고 종료 전 사용자에게 확인을 요청할 수 있게 해줍니다. 저장되지 않은 데이터를 저장하거나 실수로 종료되는 것을 방지해야 하는 앱에 특히 유용합니다. 사용자가 창을 닫으려 할 때 실행되는 콜백을 등록할 수 있는 간단한 API를 제공하여 개발자가 사용자 정의 대화 상자를 표시하거나 정리 작업을 수행할 수 있도록 합니다. 이 패키지는 macOS, Windows, Linux 및 Web을 지원하므로, 부드러운 종료 처리가 필요한 크로스플랫폼 데스크톱 앱에 이상적입니다.

사용 사례

  • 의도하지 않은 앱 종료 방지
  • 종료 전에 저장되지 않은 데이터 저장
  • 확인 대화 상자 표시
  • 데스크톱에서의 우아한 종료
  • 사용자 정의 종료 로직
  • 웹 및 데스크톱 호환성

주요 기능

  • 윈도우 닫기 이벤트를 가로챕니다
  • 여러 데스크톱 플랫폼을 지원합니다
  • 간단한 콜백 API
  • 크로스 플랫폼 桌면 지원
  • 선택적 확인 대화상자
  • 웹 및 네이티브 통합

적합한 대상

  • 데스크톱 플러터 앱
  • 저장되지 않은 데이터가 있는 앱
  • 사용자 중심의 데스크톱 애플리케이션
  • 종료 제어가 필요한 개발자
  • 확인 프롬프트가 필요한 응용 프로그램
  • 크로스 플랫폼 데스크톱 프로젝트

고려 사항

  • 모바일 플랫폼에서는 적용되지 않습니다
  • 플랫폼별 설정이 필요합니다
  • 시스템 수준의 닫기 동작과 충돌할 수 있습니다
  • 데스크톱 및 웹에 한정
  • 작업 관리자에서 앱 종료를 처리하지 않음
  • 사용자 경험은 구현에 따라 달라집니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

flutter_window_close

2021 © Weizhong Yang a.k.a zonble

Pub example workflow License: MIT

flutter_window_close lets your Flutter app has a chance to confirm if the user wants to close your app. It works on desktop platforms including Windows, macOS and Linux.

macOS Windows Linux

Example

Getting Started

It is very common that an app would prompt a message like "Do you really want to quit" when users click on the close button, in order to notify that there are still undone tasks and the users may lose their data if they want to quit anyway. It prevents the users from losing data unwillingly.

To let a Flutter desktop app to support that, the plug-in listens to the events from the window hosting Flutter's view, and send the events to Flutter. What you need to do is to assign an anonymous function that can answer if the window should be closed. For example, you can show an alert dialog to ask what the current user is willing to do:

FlutterWindowClose.setWindowShouldCloseHandler(() async {
    return await showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
          title: const Text('Do you really want to quit?'),
          actions: [
            ElevatedButton(
            onPressed: () => Navigator.of(context).pop(true),
            child: const Text('Yes')),
            ElevatedButton(
            onPressed: () => Navigator.of(context).pop(false),
            child: const Text('No')),
          ]);
        });
});

The plugin bridges following APIs:

It does not support mobile platforms, since there is no such event for closing windows. You can use a custom WillPopScope to capture if a user is leaving your app with a back key.

macOS

There could be some issues while using the package on macOS. Each platform has its paradigm and the developer framework macOS sees window objects in a different way from Windows and Linux.

On Windows and Linux, windows are more like controllers in MVC pattern , and when it comes to Flutter, there would be always a root window in the process of an app, and our plugin could easily know which is the window to listen to. In the code level, we use GetActiveWindow while we can use gtk_widget_get_ancestor or gtk_widget_get_toplevel.

On the contrary, windows are more like views on macOS. An app can have multiple windows, and the app can stay still open event all windows are closed. We can also create an object with multiple IBOutlets to multiple windows. Flutter macOS does not tell plugins which window is the one running Flutter as well.

The plugin listens to the first window in the windows list of the singleton NSApplication object. It works if you have only one window in your macOS Flutter app. If you just create a new app using the official template for macOS, you may need not to change anything. However, if your app has multiple windows, the behavior of the plugin might be unexpectable.

Flutter Web

We can do little when a user is closing the tab or window hosting your Flutter Web app. The only way to let a user to confirm if he or she really want to close is to set the return value of the onbeforeunload event. You can use the setWebReturnValue method to set the return value.

License

The package is released under MIT license.

카테고리

의존성

의존성 목록 1 개

소스 저장소

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