例如,我有SingleChildScrollView
和BouncingScrollPhysics
。当内容从边缘跳出时,我想要类似print(_overscrollOffsetValue)
的内容,例如过度滚动的偏移值越大,_overscrollOffsetValue
越大。
您可以收听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),
),
)