【问题标题】:Flutter Mouse Scroll Wheel SensitivityFlutter 鼠标滚轮灵敏度
【发布时间】:2021-04-03 06:56:53
【问题描述】:

我正在使用 Flutter 2.0 为 Windows 桌面进行开发。 使用鼠标滚轮滚动列表有点无聊,如何根据滚轮刻度设置添加项目?

【问题讨论】:

    标签: flutter listview


    【解决方案1】:

    我遇到了同样的问题,这是我找到的解决方法。 在你的小部件中,你有你的滚动元素(可以是一个列表,或者,在我的例子中,一个SingleChildScrollView),添加一个ScrollController 并添加一个监听器:

    
    class ScrollViewTest extends StatelessWidget
    {
      static const _extraScrollSpeed = 80; // your "extra" scroll speed
      final ScrollController _scrollController = ScrollController();
    
      // Constructor.
      ScrollViewTest({Key? key}) : super(key: key)
      {
        _scrollController.addListener(() {
          ScrollDirection scrollDirection = _scrollController.position.userScrollDirection;
          if (scrollDirection != ScrollDirection.idle)
          {
            double scrollEnd = _scrollController.offset + (scrollDirection == ScrollDirection.reverse
                           ? _extraScrollSpeed
                           : -_extraScrollSpeed);
            scrollEnd = min(
                     _scrollController.position.maxScrollExtent,
                     max(_scrollController.position.minScrollExtent, scrollEnd));
            _scrollController.jumpTo(scrollEnd);
          }
        });
      }
    
      @override
      Widget build(BuildContext context)
      {
        return SingleChildScrollView(
          controller: _scrollController,
          child: Container(...),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-21
      • 2011-01-30
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多