Skip to content
pubscout

flutter_window_close

1.3.0, released a year ago by zonble.net

Intercept window close events on desktop and web to confirm exiting.

WASM-ready
$ flutter pub add flutter_window_close
Source repository

What it does

Allows your Flutter application to intercept window close requests on Windows, macOS, Linux, and web platforms. It lets you run asynchronous functions such as dialog prompts to confirm if the user really wants to quit, preventing accidental data loss.

AI-written summary of version 1.3.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are building a desktop or web app and need to prompt users before they close the window if they have unsaved work.
  • You want to handle WM_CLOSE, windowShouldClose, and delete-event signals seamlessly.

Skip it when

  • Your application targets mobile platforms exclusively.
  • You have a multi-window macOS app where strict window mapping is required.

Strengths

  • Simple API to intercept window closing via handlers.
  • Supports multiple desktop platforms (Windows, macOS, Linux) and web.

Weaknesses

  • Limited multi-window support on macOS since it listens to the first window in the application list.
  • Web support is limited to the browser's onbeforeunload event limitations.

Setup

Kind
Plugin (native code)
Effort
Low
Code generation
No
Direct dependencies
1

Not documented

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')),
          ]);
        });
});

Works with

Packages commonly used together with flutter_window_close: ones it builds on, ones built on it, and its own family.