import 'dart:math'; import 'package:flutter/material.dart'; import 'package:fis_common/env/env.dart'; import 'package:flutter/rendering.dart'; import 'package:vitalapp/architecture/app_parameters.dart'; // 用于修正工作站 鼠标滚动速度过慢的问题 [弃用] class AndroidScrollWrapper extends StatefulWidget { const AndroidScrollWrapper({ super.key, required this.child, required this.controller, this.scrollSpeed = 40.0, }); final Widget child; final ScrollController controller; final double scrollSpeed; @override State createState() => _AndroidScrollWrapperState(); } class _AndroidScrollWrapperState extends State { FPlatformEnum get platform => FPlatform.current; // ScrollNotification notification; // @override // void initState() { // super.initState(); // if (platform == FPlatformEnum.android && // !AppParameters.data.isLocalStation) { // widget.controller.addListener(_onScroll); // } // } // @override // void dispose() { // widget.controller.removeListener(_onScroll); // super.dispose(); // } void _onScroll() { ScrollDirection scrollDirection = widget.controller.position.userScrollDirection; if (scrollDirection != ScrollDirection.idle) { double scrollEnd = widget.controller.offset + (scrollDirection == ScrollDirection.reverse ? widget.scrollSpeed : -widget.scrollSpeed); scrollEnd = min(widget.controller.position.maxScrollExtent, max(widget.controller.position.minScrollExtent, scrollEnd)); widget.controller.jumpTo(scrollEnd); } } @override Widget build(BuildContext context) { // if (platform == FPlatformEnum.android) { // // 如果是安卓,需要监听滚动事件,加速安卓上鼠标的滚动 // return NotificationListener( // onNotification: (ScrollNotification notification) { // if (notification is ScrollUpdateNotification) { // widget.controller.jumpTo( // widget.controller.offset + (notification.scrollDelta ?? 0)); // } // return true; // }, // child: widget.child, // ); // } return widget.child; } }