如何获取BouncingScrollPhysics超滚动值偏移量?

问题描述 投票:0回答:1

例如,我有SingleChildScrollViewBouncingScrollPhysics。当内容从边缘跳出时,我想要类似print(_overscrollOffsetValue)的内容,例如过度滚动的偏移值越大,_overscrollOffsetValue越大。

flutter flutter-layout
1个回答
0
投票

您可以收听ScrollUpdateNotification:

NotificationListener<ScrollNotification>(
  onNotification: (notification) {
    if (notification is ScrollUpdateNotification) {
      final offset = notification.metrics.pixels;
      if (offset < 0) {
        print(offset.abs());
      }
    }
    return false;
  },
  child: SingleChildScrollView(
    physics: BouncingScrollPhysics(),
    child: Text('A' * 10000),
  ),
)
© www.soinside.com 2019 - 2024. All rights reserved.