I’m working on a Flutter desktop app using the desktop_multi_window library (version 0.2.1) to handle multiple windows. I have a main window where I manage a table of parameters and a separate chart window that displays data in real-time. I’m using GetX for state management, with a view model set up as a singleton. Initially, I noticed that my chart wouldn’t update when I changed data in the main window unless I reopened it. Digging into the logs, I saw my view model being initialized multiple times—once for the main window and once for each chart window I opened.
To fix the update issue, I implemented message passing between windows, which works perfectly now—the chart updates in real-time as I modify data. But I’m still curious about why new instances of my view model are created every time I open a new window. My logs show the same initialization message repeated for each window, even though I expected a singleton to be shared across the app.
Is this behavior—creating new instances for each window—just how desktop_multi_window works? Does each window run in its own isolate, forcing this separation? And if so, does that mean the only way to share state (like variables, booleans, or any data) between windows is through the library’s own methods, like sending messages? I’d love to hear from anyone who’s used this library—what’s your take on this, and is there a cleaner way to manage state across windows?
Thanks for any thoughts!
I tried using GetX with a singleton (Get.put(..., permanent: true)) to manage state across multiple windows in my Flutter desktop app with desktop_multi_window. I expected the singleton to share the same instance of DashboardViewModel between the main window and chart windows, allowing real-time updates without re-opening. Instead, I found new instances created for each window, as shown by multiple [DashboardViewModel] Instance 0 initialized logs, and the chart only updated after reopening until I added message passing.