Reputation: 76
Problem: I have a PageView with 3 pages: P1,P2,P3. When I open an additional page on P3 (or P2) and then close that additional page, the PageView rebuilds but puts P3 as the first page.The new broken page order is P3,P2,P3.
If I exclude if (_page != 0 && position == 0) { return pageListTest[_page];}
P1 will be shown instead of P3 as position == 0
which is logical but also not the desired behavior as P3 should just be shown again.
Here is the code im using:
body: (_page > 2) ?
// if the page is not included in the page view
getPage(_page, arguments):
//if the page is included in the page view
ScrollConfiguration(
behavior: CustomScrollBehaviour(),
child: PageView.builder(
itemCount: 3,
controller: controller,
onPageChanged: (newPosition) {
bottomNavBarProvider.setPage(newPosition, newPosition);},
itemBuilder: (context, position) {
//Here is the problem: I navigate back therefore _page != 0 but position==0
if (_page != 0 && position == 0) {
return pageListTest[_page];}
return pageListTest[position];
})
Any ideas? Thanks :)
Upvotes: 0
Views: 355
Reputation: 115
Check PageView class https://api.flutter.dev/flutter/widgets/PageView-class.html There it says you need to create a page controller and add the pages as a widget children. Also, you have to set which page is the first page before defining the pageView controller.
Upvotes: 1