0

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 :)

1 Answers1

1

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.

RobHG
  • 115
  • 6
  • I created the controller also the PageView is using the controller. The initial page is 0 which is correct as the first page that should be shown is the 1. Page. But thanks anyway maybe I can rebuild the PageController with another initial start value. – Miro Liebschner Dec 11 '20 at 19:15
  • Well I solved my problem thanks to your help! I just pass the PageController the _page as initial page. – Miro Liebschner Dec 11 '20 at 19:20