By WalkingTree June 08, 2020

A PageView is a Flutter widget that creates scrollable pages on the screen. It can either create a list of a fixed number of pages or can use a builder function to create pages on demand. The PageView widget is quite similar to the ListView widget when it comes to constructing elements.
What are the different PageView constructors?
- PageView() – Creates a scrollable list of pages from an explicit list of widgets
- PageView.builder() – Creates a scrollable list of pages using widgets that are created on-demand
- PageView.custom() – Creates a scrollable list of pages with a custom child model
Not just this, you can add custom transitions, change page scrolling to horizontal or vertical, set page snapping to true or false, and customize many other things.
How does the PageView work?
The first thing you will be needing is a PageController which manages the swipe detection and provides the animation. You can use the initialPage property to set which page to start on.
1 2 3 |
final controller = PageController( initialPage: 1, ); |
Then create your page using the PageView widget and give the controller and pages to display.
1 2 3 4 5 6 7 8 |
final pageView = pageView( controller: controller, children: [ MyPage1Widget(), MyPage2Widget(), MyPage3Widget(), ], ); |
That’s it! With the help of PageView and PageController, users can swipe between different screens of the app.
Check out the Flutter widget of the week video for more information
Blogs
In recent times, due to the effects of the pandemic, a mask detecting app is in great need….
Theming is styling an application so that its look and feel matches your personal design aesthetic or that…
In this blog, we have collated the important Flutter best practices that should be kept in mind for…