首页 > 解决方案 > 如何在不使用 ListView 或 ScrollView 的情况下检测小部件中的滚动?

问题描述

我想检测小部件中的滚动,但我没有使用类似ListViewor的东西GridView。我试过GestureDetector这样使用:

void _verticalDragStart(DragStartDetails details) {
    started = details.localPosition;
  }

void _verticalDragUpdate(DragUpdateDetails details) {
   final updatedPosition = details.localPosition;
    double difference = started.dy-updatedPosition.dy;
    //use difference in my code
  }

但由于某种原因,它太快了并且给出了非常高的值。我尝试使用小部件,但如果构建器没有占用比可用空间更多的空间,Scrollable它不会更新偏移量。Viewport我能做些什么?

标签: flutter

解决方案


我认为您必须查看一个名为 ScrollNotification 的小部件。

希望它有效!


推荐阅读