如何在 GridView (Flutter) 中进行分页 [英] how to do pagination in GridView (Flutter)

查看:20
本文介绍了如何在 GridView (Flutter) 中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 GridView 中实现分页我使用 GridView.builder 我想在用户到达最后一行时下载 10 x 10 个项目

I want to implement pagination in GridView I use GridView.builder I want to download 10 by 10 items when the user reaches the last row

推荐答案

您可以使用 NotificationListener 来做到这一点.作为一个简单的演示,它会在 GridView 到达页面末尾时增加其长度:

You can do this using a NotificationListener. As a simple demonstration it will increase the length of your GridView whenever it reaches end of page :

    var items_number = 10 ;

    return NotificationListener<ScrollNotification>(
         onNotification: (scrollNotification){
              if(scrollNotification.metrics.pixels == scrollNotification.metrics.maxScrollExtent){
                 setState(() {
                    items_number += 10 ;
                 });    
              }
         },
         child: GridView.builder(
                    itemCount: items_number,
                    itemBuilder: (context, index) {
                      //.... the reminder of your code
                    }
                ),
    );

这篇关于如何在 GridView (Flutter) 中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆