android - Flutter中如何检测ListView的滚动位置

标签 android dart flutter

我正在使用 ListView 小部件将项目显示为列表。在窗口三中,查看的项目必须将中间的项目放在中间。

那么如何在滚动停止时检测 ListView 的位置?

如何检测 ListView 滚动停止?

最佳答案

我使用了 NotificationListener,它是一个小部件,用于监听在树上冒泡的通知。然后使用ScrollEndNotification,表示滚动已停止。

对于滚动位置,我使用了类型为 ScrollController_scrollController

NotificationListener(
  child: ListView(
    controller: _scrollController,
    children: ...
  ),
  onNotification: (t) {
    if (t is ScrollEndNotification) {
      print(_scrollController.position.pixels);
    }
    //How many pixels scrolled from pervious frame
    print(t.scrollDelta);

    //List scroll position
    print(t.metrics.pixels);
  },
),

关于android - Flutter中如何检测ListView的滚动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54065354/

相关文章:

dart - 如何使用DART语言解决此错误:NoSuchMethodError:找不到方法: 'readLineSync'

android - `flutter doctor`期间 flutter 崩溃

android - 如何在 RxJava 发生不同事件时得到通知?

java - 无法解析方法askCompactPermission

client-server - Dart 中的客户端服务器

flutter - 生成后 flutter 显示模态底页

unit-testing - 如何对 Flutter TextFormField maxlines 进行单元测试

android - 是否在Google Map上使用TextFormField?

java - Android单元测试如何创建ContentResolver stub ?

java - SimpleDateFormat 在将日期转换为字符串时更改日期