Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug on windowManager.setSize method #67

Closed
polilluminato opened this issue Feb 5, 2022 · 7 comments
Closed

Bug on windowManager.setSize method #67

polilluminato opened this issue Feb 5, 2022 · 7 comments

Comments

@polilluminato
Copy link

polilluminato commented Feb 5, 2022

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.

Schermata del 2022-02-05 08-52-07

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

@berkekbgz
Copy link

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.

@damywise
Copy link
Contributor

damywise commented Feb 5, 2022

Another alternative is to hide the app until it's fully started/loaded and then change the size before showing it.

@damywise
Copy link
Contributor

damywise commented Feb 5, 2022

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.

@polilluminato
Copy link
Author

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?

@damywise
Copy link
Contributor

damywise commented Feb 8, 2022

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

@polilluminato
Copy link
Author

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.

@lijy91
Copy link
Member

lijy91 commented Aug 29, 2022

A solution is proposed here #206 (comment)

@lijy91 lijy91 closed this as completed Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants