If you follow the example codes found online, when building a scaffold, under body, you can have:
body: PageView(
controller: _pageController,
onPageChanged: (index) {
setState(() => _selectedPage = index);
},
children: <Widget>[
Container(color: Colors.pink,),
Container(color: Colors.cyan,),
Container(color: Colors.deepPurple,),
],
)
When you are on the page that shows the color pink and you swipe left, a page of color cyan comes from the right. However, right now I extended it for my usecase and now have:
body: PageView(
controller: _pageController,
onPageChanged: (index) {
setState(() => _selectedPage = index);
},
children: <Widget>[
Container(child: _pageOptions[_selectedPage],),
Container(child: _pageOptions[_selectedPage],),
Container(child: _pageOptions[_selectedPage],),
],
)
The "_pageOptions[]" is defined as follows:
final _pageOptions = [
Page1(),
Page2(),
Page3(),
];
My issue is as follows: When, for example, you are on Page1 and swipe left, Page2 is supposed to come from the right and become the new page you are looking at. However, when you swipe from Page1 to Page2 slowly, you can see that the page that is coming from the right is Page1 rather than Page2. Up until you swipe halfway that the incoming page becomes Page2. However, by this point, the page that you are swiping away into the left side (which is supposed to be Page1) becomes Page2 as well.
How can I fix this? Page1() and the rest return a widget. For example, class Page1 is coded as:
class Page1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(25.0),
child: Text('Page1', style: TextStyle(fontSize: 36.0),)
);
}
}