4

I have loaded some news in my SliverList. I want to make this list dynamic. How to add pagination feature in my below code with SliverList?

FutureBuilder<List<Data>>(
    future: getNews(),
    builder: (context, snapshot){
      Widget newsListSliver;

      if(snapshot.hasData){
        newsListSliver = SliverList(

          delegate: new SliverChildBuilderDelegate((context, index){
            return new NewsList(latestNews: snapshot.data.elementAt(index),);
          }, childCount: snapshot.data.length),
        );
      }else{
        newsListSliver = SliverToBoxAdapter(child: Center(child: CircularProgressIndicator(),));
      }
      return CustomScrollView(
        slivers: <Widget>[

          SliverToBoxAdapter(child: new TabPanel()),
          SliverToBoxAdapter(child: new UrlButtonPanel()),
          SliverToBoxAdapter(child: new ChatNowAd()),

          newsListSliver
        ],
      );
    },
  )
Yeahia2508
  • 7,526
  • 14
  • 42
  • 71
  • there is far difference between listview and sliverlist. don't make duplicate without knowing the problem. – Yeahia2508 Sep 12 '18 at 14:46
  • 4
    No there's no difference between them. ListView is a sliverlist. Add the ScrollController to your CustomScrollView – Rémi Rousselet Sep 12 '18 at 14:50
  • there is no controller in sliverlist. – Yeahia2508 Sep 12 '18 at 14:50
  • 5
    You can pass a ScrollController as parameter to [CustomScrollView](https://docs.flutter.io/flutter/widgets/CustomScrollView/CustomScrollView.html). Which leads to the same answer – Rémi Rousselet Sep 12 '18 at 14:54
  • Are you satisfied with that answer, or is there truly a need to reopen it? – Rémi Rousselet Sep 12 '18 at 15:05
  • I solved my problem with some issues. Thanks anyway. – Yeahia2508 Sep 14 '18 at 07:56
  • It is true that custom scrollview has the scroll controller, however there needs to be some custom logic to determin which sliverlist is currently being served. E.g. I have two datasources A and B and a sliver list for each in a custom scrollview. You will need to determin which datasource has reached the end and which needs the next page call triggered, a little more tricky and I think could do with a nice example. – Lee Higgins Jun 07 '21 at 09:42

0 Answers0