1

I'd like to render a PageView but instead of the currentIndex for each page being numbered sequentially IE: 1,2,3,4,5,6,7,8,9 I'd like to reverse the numbering IE: 9,8,7,6,5,4,3,2,1.

Anybody know a way to do this??

PageView.builder(
        itemCount: message.length,
        itemBuilder: (context, int currentIndex) {
          return createViewItem(message[currentIndex], context, );
        },
      );
  }
Meggy
  • 1,491
  • 3
  • 28
  • 63

1 Answers1

2

try this:

PageView.builder(
        itemCount: message.length,
        itemBuilder: (context, int currentIndex) {
          return createViewItem(message[(message.length+1)-currentIndex], context, );
        },
      );
  }

if starting from the 0 index, You must decrease 1 like this:

return createViewItem(message[(message.length-1)-currentIndex], context);
farouk osama
  • 2,374
  • 2
  • 12
  • 30
  • That was a great idea, but unfortunately, it reverses the appearance order of the pages instead of the index number assigned to each page. What I wanted was to reverse the index numbers for each page. But I suspect PageView just wasn't designed to do that. – Meggy Sep 07 '20 at 20:40
  • Sorry, but I did not understand exactly what you want anyway, you have a reverse order that you can use however you want, you can change the order of the pages or assign it to the page to view it etc.. – farouk osama Sep 07 '20 at 21:23
  • As my database will be constantly updating I'd like to be able to scroll back to the last index number after refreshing. If the index numbers are in reverse any new items added to the database since will not affect the scroll position. – Meggy Sep 08 '20 at 10:59
  • I think now I'll try storing PagewView the data into an internal SQLite database and use this to to scroll back to. That way any updating of the database will not affect the scroll position. – Meggy Sep 08 '20 at 11:01
  • Sorry my friend, but until now I do not know exactly what you want, however, if you cannot find a solution to your current problem, create another question and do not forget the smallest details, 100 flowers for you – farouk osama Sep 08 '20 at 11:11