bitsdojo_window icon indicating copy to clipboard operation
bitsdojo_window copied to clipboard

Black canvas when restoring from minimize

Open LWY6670 opened this issue 3 years ago • 15 comments

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 avatar Sep 19 '21 11:09 LWY6670

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

LWY6670 avatar Sep 19 '21 11:09 LWY6670

Do you think you could record a video of this?

bitsdojo avatar Sep 19 '21 11:09 bitsdojo

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

LWY6670 avatar Sep 19 '21 11:09 LWY6670

May be you could leave me a email address

LWY6670 avatar Sep 19 '21 11:09 LWY6670

Mine email is [email protected], you can tell me yours, in an email to me.

LWY6670 avatar Sep 19 '21 11:09 LWY6670

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

bitsdojo avatar Sep 19 '21 11:09 bitsdojo

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

LWY6670 avatar Sep 19 '21 11:09 LWY6670

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

bitsdojo avatar Sep 19 '21 12:09 bitsdojo

OK. I will have a try.

LWY6670 avatar Sep 19 '21 12:09 LWY6670

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

Uploading BLACK BLOCK-issue.mp4…

LWY6670 avatar Sep 19 '21 12:09 LWY6670

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.

bitsdojo avatar Sep 19 '21 12:09 bitsdojo

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 avatar Sep 19 '21 13:09 LWY6670

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

LWY6670 avatar Sep 19 '21 13:09 LWY6670

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

chifandeyu avatar Feb 18 '22 13:02 chifandeyu

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.

cremfert avatar Aug 09 '22 15:08 cremfert