leanflutter / window_manager

This plugin allows Flutter desktop apps to resizing and repositioning the window.
https://pub.dev/packages/window_manager
MIT License
723 stars 203 forks source link

maximize() not working #412

Open maxfornacon opened 1 year ago

maxfornacon commented 1 year ago

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.

erickib commented 10 months ago

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.

trungtin0012 commented 9 months ago

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);
}
Kinwailo commented 8 months ago

I add a delay to call the maximize method:

Future.delayed(Durations.long4, () {
  if (Settings.maximize.val) windowManager.maximize();
});