bitsdojo_window
bitsdojo_window copied to clipboard
Handle/Listen close button on macOs
How to handle onClose button press on mac?
Not available at this moment but event handling support is planned (already started working on it).
@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.