New post Need visibility? Apply for a FREE post for your Startup.  Apply Here


How to implement a PageView in Flutter.

2 Mins read

Hi, everyone and welcome to a brand new tutorial series on Flutter. Today we’re going to learn how to implement PageView in Flutter.

If you haven’t already seen the Flutter Widget of the Week video about how to implement PageView in Flutter, kindly watch it first. The rest of this article is based on it.

Flutter Widget of the week – PageView.

This video showed you the essence of what PageView does. This article will fill out the code for you to play with. Scroll down to the end to get the full code demo, or just get the source code here.

PageView widget allows the user to swipe/transition between different screens in your app. All you need to set it up are a PageViewController and a PageView.

You can use a PageController to control which page is visible in the view. In addition to being able to control the pixel offset of the content inside the PageView, a PageController also lets you control the offset in terms of pages, which are increments of the viewport size.

PageController can also be used to control the PageController.initialPage, which determines which page is shown when the PageView is first constructed, and the PageController.viewportFraction, which determines the size of the pages as a fraction of the viewport size.

Exploring PageView

PageView is a widget that generates scrollable pages on the screen. This can either be a fixed list of pages or a builder function that builds repeating pages. PageView acts similarly to a Listview in the sense of constructing elements.

Three types/Constructor of PageView

we have three types of PageView just like ListView.

1. PageView
2. PageView.builder
3. PageView.custom

PageView (Default constructor)

This type takes a fixed list of children (pages) and makes them scrollable.

          children: <Widget>[
              child: Center(
                  child: Text(
                'Page 1',
                style: TextStyle(color: Colors.white),
              child: Center(
                  child: Text(
                'Page 2',
                style: TextStyle(color: Colors.white),
              child: Center(
                  child: Text(
                'Page 3',
                style: TextStyle(color: Colors.white),

The above code produce the below screen 👇


This constructor takes a itemBuilder function and an itemCount similar to ListView.builder.

  itemBuilder: (context, index) {
    return _buildPage();
  itemCount: listItemCount, // Can be null

Like a ListView.builder, this builds children on demand.

If the itemCount is set to null (not set), an infinite list of pages can be generated.

Example: The below code produce the below screen 👇

        // itemCount: 3,
        itemBuilder: (context, index) {
        return Container(
          color: index % 2 == 0 ? :[700],

Gives an infinite list of pages with alternating pink and cyan colors:

PageView.custom Constructor

   {Key key,
   Axis scrollDirection: Axis.horizontal,
   bool reverse: false,
   PageController controller,
   ScrollPhysics physics,
   bool pageSnapping: true,
   ValueChanged<int> onPageChanged,
   @required SliverChildDelegate childrenDelegate,
   DragStartBehavior dragStartBehavior: DragStartBehavior.start,
   bool allowImplicitScrolling: false,
   String restorationId,
   Clip clipBehavior: Clip.hardEdge}

PageView.custom works the same way as ListView.custom. It takes a childrenDelegat function similar to ListView.builder.
PageView.custom is more explained with examples in the source code.

Customized PageView

I hope you have learned something, kindly subscribe to the newsletter and appreciate this tutorial by sharing it and feel free to ask a question. Thanks for reading.

Source code! 👇 Show some ❤️ by starring ⭐ the repo and do follow me 😄!

Complete source code!

Join Flutter Developer Community: Telegram | Facebook | WhatsApp

Let’s connect with each other online: Github,  TwitterYoutubeMediumLinkedIn, etc.

Read also: Understanding the Flutter Architecture.

Don’t miss any tech news ever!

We don’t spam! Read our privacy policy for more info.

18 posts

About author
I'm passionate about learning and teaching programming, majorly Flutter at the moment. I make friends, develop, or learn from them.
Related posts

Oligopoly Concerns: NATCOMS Begs NCC To Halt MTN’s Move To Acquire 9mobile?

2 Mins read
In a dynamic and rapidly evolving sector like telecommunications, regulatory interventions can significantly impact the competitive landscape. Striking the right balance between… Like this:Like Loading...

Cryptocurrency: 3 Cryptos To Consider With 500x ROI Potential

2 Mins read
Amidst the waves Cryptocurrency has made since its inception, the industry has remained a mystery to some people due to its intangibility… Like this:Like Loading...
ArticleMobileRandomWeekend Vibes

Photography: Best Camera Phones In 2023

3 Mins read
Saturdays are for parties. The interesting thing about parties aside the food and the music is the scenery; and the best way… Like this:Like Loading...
Newsletter Subscription

🤞 Don’t miss any update!

We don’t spam! Read more in our privacy policy

Join our Telegram channel here -

1 Comment

Leave a Reply

%d bloggers like this: