window_manager
window_manager copied to clipboard
Bug on windowManager.setSize method
Hi everyone and thanks for this useful package! I've got a little problem with my app because I noticed a weird behaviour with the windowManager.setSize method.
When my app starts I want the size of the window to Size(385, 835)
but when I first run the app it stars much larger (I think at 800x600) and only if I re-run it with the green rounded arrow on VSCode it resizes correctly.
I also tried to use windowManager.setResizable(false)
, windowManager.setMinimumSize(const Size(385, 835))
and windowManager.setMaximumSize(const Size(385, 835))
but the behavior is similar.
In particular I noticed that if I use the setResizable() method the window is never at Size(385, 835)
, it starts big and, obviously, I cannot resize it.
This is the minimum reproducible code:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Must add this line.
await windowManager.ensureInitialized();
// Use it only after calling `hiddenWindowAtLaunch`
windowManager.waitUntilReadyToShow().then((_) async {
// Hide window title bar
if (!Platform.isLinux) {
await windowManager.setTitleBarStyle('hidden');
}
/*The weird behaviour is here*/
await windowManager.setResizable(false);
await windowManager.setSize(const Size(385, 835));
await windowManager.setMinimumSize(const Size(385, 835));
await windowManager.setMaximumSize(const Size(385, 835));
/*The weird behaviour is here*/
await windowManager.center();
await windowManager.show();
await windowManager.focus();
await windowManager.setSkipTaskbar(false);
});
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Container(),
);
}
}
This is my flutter doctor
[✓] Flutter (Channel stable, 2.10.0, on Fedora Linux 35 (Workstation Edition)
5.15.18-200.fc35.x86_64, locale it_IT.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] VS Code (version 1.63.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
Thanks, Alberto
I think it happening because c++ works before then dart code. So if you even fix this issue (in dart) it will flicker and it cause another issue.
One way to fix this is to change the native code. (I dont know if there is another way to fix it)
For linux:
linux/my_application.cc
static void my_application_activate(GApplication* application) {
// ...
gtk_window_set_default_size(window, 1280, 720); //<-- You should change that
//...
}
For windows:
windows/runner/main.cpp
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// ...
Win32Window::Size size(1280, 720); //<--You should change that
// ...
}
For macos: Sorry i didnt find the size configuration for macos but this might be helpful https://stackoverflow.com/a/63343290
I hope this will fix your issue.
My english is not so very well. I apologize if i made a mistake or misunderstood.
Another alternative is to hide the app until it's fully started/loaded and then change the size before showing it.
Also to note: On Windows, windowManager.setResizable(...) is only disabling the manual resize borders so hovering and clicking the borders won't do anything and the app is still resizable using code.
Another alternative is to hide the app until it's fully started/loaded and then change the size before showing it.
What's the code for that?
What's the code for that?
Do this Hide at launch and then add this code (like in usage example)
windowManager.waitUntilReadyToShow().then((_) async {
// ... maybe some code
await windowManager.setSize(Size(800, 600));
// ... maybe some other code
});
Sorry for the late response
I saw the Hide at launch section but unfortunately there's no information on how to handle linux. Anyway the issue appears only when the app first start, if I then press the green rounded arrow on VSCode it resizes and for now I'm fine with that.
I run the app as Linux Desktop app only on development because is faster than the Android Emulator.
A solution is proposed here https://github.com/leanflutter/window_manager/issues/206#issuecomment-1229541016