How to get BouncingScrollPhysics overscroll value offset?

Viewed 635

For example, I have SingleChildScrollView with BouncingScrollPhysics. I want something like print(_overscrollOffsetValue) when content jumps from edge, e.g. the more offset value of overscroll, the bigger _overscrollOffsetValue.

1 Answers

You can listen for 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),
  ),
)
Related