how to do pagination in GridView (Flutter)

Question

Asked by ahmed k on May 27, 2019 (source).

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

Answer

Question answered by Mazin I (source).

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
                    }
                ),
    );
DART FLUTTER FLUTTER-LAYOUT
SHARE: