123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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 AndroidGlobalScrollFix extends StatefulWidget {
- const AndroidGlobalScrollFix({
- super.key,
- required this.child,
- this.scrollSpeed = 40.0,
- });
- final Widget child;
- final double scrollSpeed;
- @override
- State<AndroidGlobalScrollFix> createState() => _AndroidGlobalScrollFixState();
- }
- class _AndroidGlobalScrollFixState extends State<AndroidGlobalScrollFix> {
- FPlatformEnum get platform => FPlatform.current;
- @override
- void initState() {
- super.initState();
- }
- @override
- void dispose() {
- super.dispose();
- }
- // 监听全局滚动 通过 BuildContext 来访问到当前激活的ScrollController
- @override
- Widget build(BuildContext context) {
- // return widget.child;
- if (platform == FPlatformEnum.android &&
- AppParameters.data.isLocalStation) {
- // 如果是安卓,需要监听滚动事件,加速安卓上鼠标的滚动
- return NotificationListener<ScrollNotification>(
- onNotification: (ScrollNotification notification) {
- if (notification is ScrollUpdateNotification) {
- final detail = notification.dragDetails;
- if (detail != null) {
- return true;
- }
- if (notification.context != null) {
- ScrollController? scrollController =
- Scrollable.of(notification.context!).widget.controller;
- if (scrollController != null) {
- ScrollDirection scrollDirection =
- scrollController.position.userScrollDirection;
- if (scrollDirection != ScrollDirection.idle) {
- double scrollEnd = scrollController.offset +
- (scrollDirection == ScrollDirection.reverse
- ? widget.scrollSpeed
- : -widget.scrollSpeed);
- scrollEnd = min(
- scrollController.position.maxScrollExtent,
- max(scrollController.position.minScrollExtent,
- scrollEnd));
- scrollController.jumpTo(scrollEnd);
- }
- }
- }
- }
- return true;
- },
- child: widget.child,
- );
- } else {
- return widget.child;
- }
- }
- }
|