From 91da949482e0e43c2c415e9fed804b72a988cc4c Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 5 Oct 2022 00:22:40 +0800 Subject: [PATCH] flutter_desktop: remote page scroll whell on track Signed-off-by: fufesou --- flutter/lib/desktop/pages/remote_page.dart | 67 +++++++++++++--------- flutter/lib/models/model.dart | 16 +++--- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 1d7a499e5..eb070a676 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -9,15 +9,17 @@ import 'package:get/get.dart'; import 'package:provider/provider.dart'; import 'package:wakelock/wakelock.dart'; import 'package:flutter_custom_cursor/flutter_custom_cursor.dart'; +import 'package:flutter_improved_scrolling/flutter_improved_scrolling.dart'; +import '../../consts.dart'; import '../../common/widgets/overlay.dart'; import '../../common/widgets/remote_input.dart'; -import '../widgets/remote_menubar.dart'; import '../../common.dart'; import '../../mobile/widgets/dialog.dart'; import '../../models/model.dart'; import '../../models/platform_model.dart'; import '../../common/shared_state.dart'; +import '../widgets/remote_menubar.dart'; bool _isCustomCursorInited = false; final SimpleWrapper _firstEnterImage = SimpleWrapper(false); @@ -89,7 +91,7 @@ class _RemotePageState extends State _updateTabBarHeight(); Get.put(_ffi, tag: widget.id); - _ffi.start(widget.id, tabBarHeight: super.widget.tabBarHeight); + _ffi.start(widget.id); WidgetsBinding.instance.addPostFrameCallback((_) { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); _ffi.dialogManager @@ -341,30 +343,43 @@ class ImagePaint extends StatelessWidget { } Widget _buildCrossScrollbar(Widget child) { - final physicsVertical = - cursorOverImage.value ? const NeverScrollableScrollPhysics() : null; - final physicsHorizontal = - cursorOverImage.value ? const NeverScrollableScrollPhysics() : null; - return Scrollbar( - controller: _vertical, - thumbVisibility: false, - trackVisibility: false, - child: Scrollbar( - controller: _horizontal, - thumbVisibility: false, - trackVisibility: false, - notificationPredicate: (notif) => notif.depth == 1, - child: SingleChildScrollView( - controller: _vertical, - physics: physicsVertical, - child: SingleChildScrollView( - controller: _horizontal, - scrollDirection: Axis.horizontal, - physics: physicsHorizontal, - child: child, - ), - ), - )); + final scrollConfig = CustomMouseWheelScrollConfig( + scrollDuration: kDefaultScrollDuration, + scrollCurve: Curves.linearToEaseOut, + mouseWheelTurnsThrottleTimeMs: + kDefaultMouseWheelThrottleDuration.inMilliseconds, + scrollAmountMultiplier: kDefaultScrollAmountMultiplier); + return Obx(() => ImprovedScrolling( + scrollController: _vertical, + enableCustomMouseWheelScrolling: cursorOverImage.isFalse, + customMouseWheelScrollConfig: scrollConfig, + child: ImprovedScrolling( + scrollController: _horizontal, + enableCustomMouseWheelScrolling: cursorOverImage.isFalse, + customMouseWheelScrollConfig: scrollConfig, + child: Scrollbar( + controller: _vertical, + thumbVisibility: false, + trackVisibility: false, + child: Scrollbar( + controller: _horizontal, + thumbVisibility: false, + trackVisibility: false, + notificationPredicate: (notif) => notif.depth == 1, + child: SingleChildScrollView( + controller: _vertical, + physics: cursorOverImage.isTrue + ? const NeverScrollableScrollPhysics() + : null, + child: SingleChildScrollView( + controller: _horizontal, + scrollDirection: Axis.horizontal, + physics: cursorOverImage.isTrue + ? const NeverScrollableScrollPhysics() + : null, + child: child, + ), + )))))); } Widget _buildListener(Widget child) { diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 6df5f3d50..833ab32a0 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -341,7 +341,7 @@ class ImageModel with ChangeNotifier { ImageModel(this.parent); - onRgba(Uint8List rgba, double tabBarHeight) { + onRgba(Uint8List rgba) { if (_waitForImage) { _waitForImage = false; parent.target?.dialogManager.dismissAll(); @@ -355,14 +355,14 @@ class ImageModel with ChangeNotifier { if (parent.target?.id != pid) return; try { // my throw exception, because the listener maybe already dispose - update(image, tabBarHeight); + update(image); } catch (e) { debugPrint('update image: $e'); } }); } - update(ui.Image? image, double tabBarHeight) async { + update(ui.Image? image) async { if (_image == null && image != null) { if (isWebDesktop || isDesktop) { await parent.target?.canvasModel.updateViewStyle(); @@ -370,7 +370,7 @@ class ImageModel with ChangeNotifier { } else { final size = MediaQueryData.fromWindow(ui.window).size; final canvasWidth = size.width; - final canvasHeight = size.height - tabBarHeight; + final canvasHeight = size.height; final xscale = canvasWidth / image.width; final yscale = canvasHeight / image.height; parent.target?.canvasModel.scale = min(xscale, yscale); @@ -1052,9 +1052,7 @@ class FFI { /// Start with the given [id]. Only transfer file if [isFileTransfer], only port forward if [isPortForward]. void start(String id, - {bool isFileTransfer = false, - bool isPortForward = false, - double tabBarHeight = 0.0}) { + {bool isFileTransfer = false, bool isPortForward = false}) { assert(!(isFileTransfer && isPortForward), 'more than one connect type'); if (isFileTransfer) { connType = ConnType.fileTransfer; @@ -1083,7 +1081,7 @@ class FFI { debugPrint('json.decode fail1(): $e, ${message.field0}'); } } else if (message is Rgba) { - imageModel.onRgba(message.field0, tabBarHeight); + imageModel.onRgba(message.field0); } } }(); @@ -1108,7 +1106,7 @@ class FFI { } bind.sessionClose(id: id); id = ''; - imageModel.update(null, 0.0); + imageModel.update(null); cursorModel.clear(); ffiModel.clear(); canvasModel.clear();