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

Max*_*yba 5 flutter flutter-layout

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

Pav*_*vel 4

您可以监听 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),
  ),
)
Run Code Online (Sandbox Code Playgroud)