macosui / macos_ui

Flutter widgets and themes implementing the current macOS design language.
https://macosui.github.io/macos_ui/#/
MIT License
1.81k stars 178 forks source link

On Dispose not triggered if closing a new window when using with MacosApp Widget: [package:desktop_multi_window] #421

Closed pauli2406 closed 1 year ago

pauli2406 commented 1 year ago

Description

I am currently building an application with this package for macOS. In this app, I am using the plugin package:desktop_multi_window which allows me to use multiple windows. It was configured using your CLI.

In the application I am building I make use of the dispose() method to release different controllers onClose of this widget. Unfortunately, it seems that if a user closes a window by clicking the red close button is not trigger this lifecycle.

image

Is it possible that the close method used with this button is ignoring the flutter lifecycle?

Or am I doing something wrong?

pauli2406 commented 1 year ago

Nvm, managed to fix it. The trick is to also add the dependency "window_manager"

Then extend the main widget of the new window with WindowListener

class _MainWidgetState extends State<MainWidget> with WindowListener {

     @override
  void onWindowClose() async {
    // Execute the logic here instead of on dispose
    super.onWindowClose();
  }
}