From 55218c0cb032731d5ff6ffaf8414594724bcd0c0 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 2 Nov 2022 09:28:41 +0800 Subject: [PATCH] flutter_desktop: fix layout size computation Signed-off-by: fufesou --- flutter/lib/desktop/pages/remote_page.dart | 11 +++++++---- flutter/lib/models/model.dart | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 6fdf44dac..89050458d 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -443,11 +443,14 @@ class ImagePaint extends StatelessWidget { Widget _buildCrossScrollbar(BuildContext context, Widget child, Size size) { var layoutSize = MediaQuery.of(context).size; + // If minimized, w or h may be negative here. + final w = layoutSize.width - kWindowBorderWidth * 2; + final h = + layoutSize.height - kWindowBorderWidth * 2 - kDesktopRemoteTabBarHeight; layoutSize = Size( - layoutSize.width - kWindowBorderWidth * 2, - layoutSize.height - - kWindowBorderWidth * 2 - - kDesktopRemoteTabBarHeight); + w < 0 ? 0 : w, + h < 0 ? 0 : h, + ); bool overflow = layoutSize.width < size.width || layoutSize.height < size.height; return overflow diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index ff26296da..d8fdca2bc 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -577,8 +577,10 @@ class CanvasModel with ChangeNotifier { Size get size { final size = MediaQueryData.fromWindow(ui.window).size; - return Size(size.width - windowBorderWidth * 2, - size.height - tabBarHeight - windowBorderWidth * 2); + // If minimized, w or h may be negative here. + double w = size.width - windowBorderWidth * 2; + double h = size.height - tabBarHeight - windowBorderWidth * 2; + return Size(w < 0 ? 0 : w, h < 0 ? 0 : h); } moveDesktopMouse(double x, double y) {