bitsdojo / bitsdojo_window

A Flutter package that makes it easy to customize and work with your Flutter desktop app window.
http://www.youtube.com/watch?v=bee2AHQpGK4
MIT License
815 stars 229 forks source link

Black canvas when restoring from minimize #106

Open LWY6670 opened 3 years ago

LWY6670 commented 3 years ago

On my Win10:

  1. All app area will be BLACK after restored from minimized.

  2. BLACK block appeared: after I adjusted the app border to make it larger when some part was off the screen, I drag it back to the center of the screen, the enlarged part of the off-screen part will not be rendered.

  3. Still BLACK gap rendering issue when I am using 2 screens which have a gap in between: after restored from maximized, the app will span over 2 screens, move the position of the app, you will find the BLACK gap.

LWY6670 commented 3 years ago

I was using the official example in \bitsdojo_window\example\

bitsdojo commented 3 years ago

Do you think you could record a video of this?

LWY6670 commented 3 years ago

OK. But I don't know where can I put the video.

LWY6670 commented 3 years ago

May be you could leave me a email address

LWY6670 commented 3 years ago

Mine email is LWY6670@163.com, you can tell me yours, in an email to me.

bitsdojo commented 3 years ago

Any file storage service like OneDrive or Google Drive that can create a public link would work for uploading the video.

LWY6670 commented 3 years ago

It's not easy for me. I am in china.

bitsdojo commented 3 years ago

Can you record a video and drag it on this page here when writing a reply?

LWY6670 commented 3 years ago

OK. I will have a try.

LWY6670 commented 3 years ago

https://user-images.githubusercontent.com/27002679/133927031-e23af998-66f6-4226-9f34-feb2174c257c.mp4

Uploading BLACK BLOCK-issue.mp4…

bitsdojo commented 3 years ago

Please try running the same tests (moving the window outside of the screen) using a normal Flutter app created using flutter create sample_app and let me know if you see the black blocks.

LWY6670 commented 3 years ago

For a official Flutter sample, the BLACK block INDEED appeared TOO, althought it would be automatically fixed in ONE sec. And when it was restored from minimized, it worked ok.

LWY6670 commented 3 years ago

https://user-images.githubusercontent.com/27002679/133928930-ec60f101-ef9f-4a9b-86c6-6dbf96321005.mp4

chifandeyu commented 2 years ago

你好,我也遇到类似的问题,把窗口一部分拖到屏幕区域外后最大化,恢复窗口大小,再拖会屏幕区域内,会出现一大块黑色区域,这是flutter的bug吧?

cremfert commented 2 years ago

Might not be the best solution, but this works for me: Define two variables in your main.dart and turn the main widget into a stateful widget (by default it is stateless):

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  _MyApp createState() => _MyApp();
}

class _MyApp extends State<MyApp> {
  late Timer restoreTimerForRefresh;
  bool _isMinimized = false;
  ...

Then implement this code in initState and dispose:

 @override
  void initState() {
    super.initState();
    restoreTimerForRefresh = Timer.periodic(const Duration(milliseconds: 100), (timer) {
      if (appWindow.size < appWindowSize) {
        _isMinimized = true;
      }

      if (appWindow.size >= appWindowSize) {
        if (_isMinimized) {
          setState(() {});
        }
        _isMinimized = false;
      }
    });
  }

  @override
  void dispose() {
    super.dispose();
    restoreTimerForRefresh.cancel();
  }

appWindowSize is defined as the minimum size of the window:

Size appWindowSize = const Size(400, 700);
void main(List<String> args) {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
  doWhenWindowReady(() {
    final win = appWindow;
    win.size = appWindowSize;
    win.minSize = appWindowSize;
    win.show();
  });
}

The timer tracks the window size (which is smaller then minSize if the window is minimized) and on restore (size is greater or equal appWindowSize), it calls setState which forces a re-render and hence removes the "black canvas".

Hope, this helps someone. If we would have a onRestore listener like promised in #95, then setState could be called in the callback. But at the moment, there is no listener.