window_manager
window_manager copied to clipboard
maximize() not working
windowManager.maximize()
is not working.
I use it like this: It appears to be maximized for a short time, but then immediately returns to its default size.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow(null, () async {
await windowManager.maximize();
await windowManager.show();
await windowManager.focus();
});
runApp(const MyApp());
}
Tested on Windows 10 with Flutter 3.13.7.
Same problem here using Windows 11 Pro, but I don't think is related to the system. Maybe windowmanager is been called again and setting the size somehow.
After some searching, I have found a workaround. You need to update in windows/runner/win32_window.cpp by changing the parameter in the ShowWindow function from SW_SHOWNORMAL to SW_MAXIMIZE (https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow).
bool Win32Window::Show() {
return ShowWindow(window_handle_, SW_MAXIMIZE);
}
I add a delay to call the maximize method:
Future.delayed(Durations.long4, () {
if (Settings.maximize.val) windowManager.maximize();
});