Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle/Listen close button on macOs #241

Open
hungryemon opened this issue Dec 26, 2023 · 2 comments
Open

Handle/Listen close button on macOs #241

hungryemon opened this issue Dec 26, 2023 · 2 comments

Comments

@hungryemon
Copy link

How to handle onClose button press on mac?

@bitsdojo
Copy link
Owner

bitsdojo commented Jan 5, 2024

Not available at this moment but event handling support is planned (already started working on it).

@YorekLiu
Copy link

YorekLiu commented Jan 23, 2024

@hungryemon using flutter AppLifecycleListener#onExitRequested, just like this:

class AppPage extends StatefulWidget {
  const AppPage({super.key});

  @override
  State<AppPage> createState() => _AppPageState();
}

class _AppPageState extends State<AppPage> {
  late AppLifecycleListener _appLifecycleListener;

  @override
  void initState() {
    super.initState();
    _appLifecycleListener = AppLifecycleListener(
      onExitRequested: _onExitRequested,
    );
  }

  Future<AppExitResponse> _onExitRequested() async {
    // save some data to disk
    await SettingsService().updateWindowSize(appWindow.size);
    await WorkspaceService().saveWorkspace();

    return AppExitResponse.exit;
  }
...

If you don't allow close app, just return AppExitResponse.cancel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants