android_scroll_wrapper.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. import 'package:fis_common/env/env.dart';
  4. import 'package:flutter/rendering.dart';
  5. import 'package:vitalapp/architecture/app_parameters.dart';
  6. // 用于修正工作站 鼠标滚动速度过慢的问题 [弃用]
  7. class AndroidScrollWrapper extends StatefulWidget {
  8. const AndroidScrollWrapper({
  9. super.key,
  10. required this.child,
  11. required this.controller,
  12. this.scrollSpeed = 40.0,
  13. });
  14. final Widget child;
  15. final ScrollController controller;
  16. final double scrollSpeed;
  17. @override
  18. State<AndroidScrollWrapper> createState() => _AndroidScrollWrapperState();
  19. }
  20. class _AndroidScrollWrapperState extends State<AndroidScrollWrapper> {
  21. FPlatformEnum get platform => FPlatform.current;
  22. // ScrollNotification notification;
  23. // @override
  24. // void initState() {
  25. // super.initState();
  26. // if (platform == FPlatformEnum.android &&
  27. // !AppParameters.data.isLocalStation) {
  28. // widget.controller.addListener(_onScroll);
  29. // }
  30. // }
  31. // @override
  32. // void dispose() {
  33. // widget.controller.removeListener(_onScroll);
  34. // super.dispose();
  35. // }
  36. void _onScroll() {
  37. ScrollDirection scrollDirection =
  38. widget.controller.position.userScrollDirection;
  39. if (scrollDirection != ScrollDirection.idle) {
  40. double scrollEnd = widget.controller.offset +
  41. (scrollDirection == ScrollDirection.reverse
  42. ? widget.scrollSpeed
  43. : -widget.scrollSpeed);
  44. scrollEnd = min(widget.controller.position.maxScrollExtent,
  45. max(widget.controller.position.minScrollExtent, scrollEnd));
  46. widget.controller.jumpTo(scrollEnd);
  47. }
  48. }
  49. @override
  50. Widget build(BuildContext context) {
  51. // if (platform == FPlatformEnum.android) {
  52. // // 如果是安卓,需要监听滚动事件,加速安卓上鼠标的滚动
  53. // return NotificationListener<ScrollNotification>(
  54. // onNotification: (ScrollNotification notification) {
  55. // if (notification is ScrollUpdateNotification) {
  56. // widget.controller.jumpTo(
  57. // widget.controller.offset + (notification.scrollDelta ?? 0));
  58. // }
  59. // return true;
  60. // },
  61. // child: widget.child,
  62. // );
  63. // }
  64. return widget.child;
  65. }
  66. }