window_manager icon indicating copy to clipboard operation
window_manager copied to clipboard

[Important] [Windows] Distortion of window while starting up

Open KRTirtho opened this issue 1 year ago • 12 comments

After upgrading to Flutter 3.22.1, Window manager is causing the entire UI to be glitched out (distorted) initially after launch.

This is how it looks image

If I turn off/comment out windowManager.ensureInitialized and windowManager.waitUntilReadyToShow function calls, the app shows up completely fine except the Title bar is visible (as expected).

There are no errors/exceptions being thrown at the Console. So, I guess this is caused any embedder change in Flutter engine?

Reverting back to Flutter 3.19.x fixes the issue though

Upstream issue: https://github.com/KRTirtho/spotube/issues/1553

Thanks for your amazing work and the plugin @lijy91 ❤️ Please fix this as soon as possible. Lots of users are affected by it.

KRTirtho avatar Jun 05 '24 16:06 KRTirtho

There were lots of changes in the Windows embeder EGL which probably lead to this kind of issues. Special focus: https://docs.flutter.dev/release/release-notes/release-notes-3.22.0#desktop

KRTirtho avatar Jun 05 '24 16:06 KRTirtho

image image I encountered the same problem, but I found a solution that requires modifying the size in the main.cpp default file to be the same as the set minimum value to fix it。

Linij avatar Jul 21 '24 14:07 Linij

I tried your fix but the issue comes back after opening the app 2/3 times.

KRTirtho avatar Jul 26 '24 04:07 KRTirtho

There's a workaround suggested by Far Se on Flutter Discord that allows to use Flutter v3.22.x with window_manager in Windows

    WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) async {
      if (Theme.of(context).platform != TargetPlatform.windows) return;
      await Future<void>.delayed(const Duration(milliseconds: 100), () {
        windowManager.getSize().then((Size value) {
          windowManager.setSize(
            Size(value.width + 1, value.height + 1),
          );
        });
      });
    });

Add following in the root App's (the very first widget where MaterialApp or CupertinoApp gets returned) initState method

KRTirtho avatar Jul 26 '24 09:07 KRTirtho

OK,I will try this. Thinks.

Linij avatar Jul 26 '24 11:07 Linij

This method is feasible, but I think it may be better。

WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) async {
      if (Theme.of(context).platform != TargetPlatform.windows) return;
      await Future<void>.delayed(const Duration(milliseconds: 100), () {
        windowManager.getSize().then((Size value) {
          windowManager.setSize(
            Size(value.width + 1, value.height + 1),
          );
          windowManager.setSize(
            Size(value.width, value.height),
          );
        });
      });
    });  

Linij avatar Jul 28 '24 08:07 Linij

I also encountered this issue, but the suggested solution didn't worked for me - on Flutter 3.24.3.

Somewhere in the widget tree, after creating the MaterialApp, a Lottie was being played using a controller - but it was rendering only when it was done loading from the asset file. So I decided to have something rendering while the lottie was loading and it worked.

maznnwell avatar Oct 03 '24 22:10 maznnwell

hey @lijy91 if you can look into this issue when you get time? Lots of users are suffering for this. I'm also not finding any clue why this might happen.

KRTirtho avatar Oct 13 '24 07:10 KRTirtho

I found a hacky solution.

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
      await windowManager.maximize();
      await windowManager.unmaximize();
    });
    super.initState();
  }

leeys0207 avatar Oct 26 '24 11:10 leeys0207

We also have this issue in AppFlowy, we ended up switching to bitsdojo on windows rather than window_manager.

I want to switch back, but the workarounds are hacky (and not usable for all cases) and ends up with a bad user experience.

Xazin avatar Nov 07 '24 12:11 Xazin

On Spotube's case, both window_managerand bitsdojo_window are having the same issue. How well does bitsdojo_window work for AppFlowy?

KRTirtho avatar Dec 01 '24 11:12 KRTirtho

On Spotube's case, both window_managerand bitsdojo_window are having the same issue. How well does bitsdojo_window work for AppFlowy?

It has the same issue, but seems to happen less frequently, not really anything I can prove though.

We prefer window_manager though, but we don't have the expertise to resolve this issue on the native front, nor the manpower atm.

Xazin avatar Dec 02 '24 14:12 Xazin