首页 > 解决方案 > 如何在 GridView (Flutter) 中进行分页

问题描述

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

标签: flutterdartflutter-layout

解决方案


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

    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
                    }
                ),
    );

推荐阅读