{"id":13547931,"url":"https://github.com/zonble/flutter_window_close","last_synced_at":"2025-10-28T02:07:51.717Z","repository":{"id":42209623,"uuid":"431772891","full_name":"zonble/flutter_window_close","owner":"zonble","description":"Helps your Flutter apps to handle window close events.","archived":false,"fork":false,"pushed_at":"2025-03-23T08:36:52.000Z","size":88127,"stargazers_count":45,"open_issues_count":1,"forks_count":18,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-09T15:07:23.715Z","etag":null,"topics":["flutter","flutter-desktop","flutter-plugin"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/flutter_window_close","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zonble.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-25T08:44:15.000Z","updated_at":"2025-04-06T00:56:28.000Z","dependencies_parsed_at":"2023-11-25T18:31:18.017Z","dependency_job_id":"2693f8f5-62f5-4e9b-b533-717024b0aeee","html_url":"https://github.com/zonble/flutter_window_close","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2Fflutter_window_close","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2Fflutter_window_close/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2Fflutter_window_close/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2Fflutter_window_close/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zonble","download_url":"https://codeload.github.com/zonble/flutter_window_close/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055284,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flutter","flutter-desktop","flutter-plugin"],"created_at":"2024-08-01T12:01:03.278Z","updated_at":"2025-10-28T02:07:46.692Z","avatar_url":"https://github.com/zonble.png","language":"C++","readme":"# flutter_window_close\n\n2021 © Weizhong Yang a.k.a zonble\n\n[![Pub](https://img.shields.io/pub/v/flutter_window_close.svg)](https://pub.dartlang.org/packages/flutter_window_close) [![example workflow](https://github.com/zonble/flutter_window_close/actions/workflows/ci.yaml/badge.svg)](https://github.com/zonble/flutter_window_close/actions) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/zonble/flutter_window_close/blob/main/LICENSE)\n\nflutter_window_close lets your Flutter app has a chance to confirm if the user\nwants to close your app. It works on desktop platforms including Windows, macOS\nand Linux.\n\n![macOS](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge\u0026logo=macos\u0026logoColor=F0F0F0)\n![Windows](https://img.shields.io/badge/Windows-0078D6?style=for-the-badge\u0026logo=windows\u0026logoColor=white)\n![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge\u0026logo=linux\u0026logoColor=black)\n\n![Example](https://raw.githubusercontent.com/zonble/flutter_window_close/main/close.gif)\n\n## Getting Started\n\nIt is very common that an app would prompt a message like \"Do you really want to\nquit\" when users click on the close button, in order to notify that there are\nstill undone tasks and the users may lose their data if they want to quit\nanyway. It prevents the users from losing data unwillingly.\n\nTo let a Flutter desktop app to support that, the plug-in listens to the events\nfrom the window hosting Flutter's view, and send the events to Flutter. What you\nneed to do is to assign an anonymous function that can answer if the window\nshould be closed. For example, you can show an alert dialog to ask what the\ncurrent user is willing to do:\n\n```dart\nFlutterWindowClose.setWindowShouldCloseHandler(() async {\n    return await showDialog(\n        context: context,\n        builder: (context) {\n          return AlertDialog(\n          title: const Text('Do you really want to quit?'),\n          actions: [\n            ElevatedButton(\n            onPressed: () =\u003e Navigator.of(context).pop(true),\n            child: const Text('Yes')),\n            ElevatedButton(\n            onPressed: () =\u003e Navigator.of(context).pop(false),\n            child: const Text('No')),\n          ]);\n        });\n});\n```\n\nThe plugin bridges following APIs:\n\n- Windows:\n  [WM_CLOSE](https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-close)\n  message in WinProc\n- macOS:\n  [windowShouldClose(\\_:)](https://developer.apple.com/documentation/appkit/nswindowdelegate/1419380-windowshouldclose)\n  in\n  [NSWindowDelegate](https://developer.apple.com/documentation/appkit/nswindowdelegate)\n- Linux:\n  [Widget::delete-event](https://docs.gtk.org/gtk3/signal.Widget.delete-event.html)\n  signal\n\nIt does not support mobile platforms, since there is no such event for closing\nwindows. You can use a custom\n[WillPopScope](https://api.flutter.dev/flutter/widgets/WillPopScope-class.html)\nto capture if a user is leaving your app with a back key.\n\n## macOS\n\nThere could be some issues while using the package on macOS. Each platform has\nits paradigm and the developer framework macOS sees window objects in a\ndifferent way from Windows and Linux.\n\nOn Windows and Linux, windows are more like controllers in MVC pattern , and\nwhen it comes to Flutter, there would be always a root window in the process of\nan app, and our plugin could easily know which is the window to listen to. In\nthe code level, we use\n[GetActiveWindow](https://docs.microsoft.com/windows/win32/api/winuser/nf-winuser-getactivewindow)\nwhile we can use\n[gtk_widget_get_ancestor](https://people.gnome.org/~shaunm/girdoc/C/Gtk.Widget.get_ancestor.html)\nor\n[gtk_widget_get_toplevel](https://people.gnome.org/~shaunm/girdoc/C/Gtk.Widget.get_toplevel.html).\n\nOn the contrary, windows are more like views on macOS. An app can have multiple\nwindows, and the app can stay still open event all windows are closed. We can\nalso create an object with multiple IBOutlets to multiple windows. Flutter macOS\ndoes not tell plugins which window is the one running Flutter as well.\n\nThe plugin listens to the first window in the\n[windows](https://developer.apple.com/documentation/appkit/nsapplication/1428402-windows)\nlist of the singleton\n[NSApplication](https://developer.apple.com/documentation/appkit/nsapplication)\nobject. It works if you have only one window in your macOS Flutter app. If you\njust create a new app using the official template for macOS, you may need not to\nchange anything. However, if your app has multiple windows, the behavior of the\nplugin might be unexpectable.\n\n## Flutter Web\n\nWe can do little when a user is closing the tab or window hosting your Flutter\nWeb app. The only way to let a user to confirm if he or she really want to close\nis to set the return value of the\n[onbeforeunload](https://developer.mozilla.org/docs/Web/API/WindowEventHandlers/onbeforeunload)\nevent. You can use the `setWebReturnValue` method to set the return value.\n\n## License\n\nThe package is released under MIT license.\n","funding_links":[],"categories":["C++","Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzonble%2Fflutter_window_close","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzonble%2Fflutter_window_close","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzonble%2Fflutter_window_close/lists"}