flutter 滑动监听,上拉加载 下拉刷新

具体代码如下,
_handleScrollNotification中做自己的上拉和下拉逻辑,我这是简单的,需要自己进行优化
new NotificationListener<ScrollNotification>(
    onNotification: _handleScrollNotification,
    child: new ListView.builder(
    controller: scrollController,
    itemBuilder: (BuildContext ctx, int index) {
      return new BookItemView(
        book: _items[index],
        searchKey: _searchText,
        words: _words,
      );
    },
    itemCount: _items?.length ?? 0,

))

bool _handleScrollNotification(ScrollNotification notification) {
//ScrollUpdateNotification 还有其他可使用,需要自行优化
  if(notification is ScrollEndNotification){
    //下滑到最底部
    if(notification.metrics.extentAfter==0.0){

    }
    //滑动到最顶部
    if(notification.metrics.extentBefore==0.0){

    }
  }
  return false;
}

猜你喜欢

转载自blog.csdn.net/qq_32319999/article/details/80423536
今日推荐