flutter_desktop: remote page scroll whell on track

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-10-05 00:22:40 +08:00
parent 048fc40882
commit 91da949482
2 changed files with 48 additions and 35 deletions

View File

@ -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<bool> _firstEnterImage = SimpleWrapper(false);
@ -89,7 +91,7 @@ class _RemotePageState extends State<RemotePage>
_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,11 +343,21 @@ class ImagePaint extends StatelessWidget {
}
Widget _buildCrossScrollbar(Widget child) {
final physicsVertical =
cursorOverImage.value ? const NeverScrollableScrollPhysics() : null;
final physicsHorizontal =
cursorOverImage.value ? const NeverScrollableScrollPhysics() : null;
return Scrollbar(
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,
@ -356,15 +368,18 @@ class ImagePaint extends StatelessWidget {
notificationPredicate: (notif) => notif.depth == 1,
child: SingleChildScrollView(
controller: _vertical,
physics: physicsVertical,
physics: cursorOverImage.isTrue
? const NeverScrollableScrollPhysics()
: null,
child: SingleChildScrollView(
controller: _horizontal,
scrollDirection: Axis.horizontal,
physics: physicsHorizontal,
physics: cursorOverImage.isTrue
? const NeverScrollableScrollPhysics()
: null,
child: child,
),
),
));
))))));
}
Widget _buildListener(Widget child) {

View File

@ -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();