How to enable paging in Flutter GridView?

3,078

Solution 1

Use PageView instead of GridView. Refer following code.

new PageView.builder(
  scrollDirection: Axis.horizontal,
  itemCount: item.length,
  itemBuilder: (context, i) {
    return new Container();
  }
)

Solution 2

Frankenstein explained perfectly moreover i will add some additional information regarding moving pageView to specific page.

1)Add PageController to your PageView like below.

`final _pageController = PageController(initialPage: 0);`

2)Call JumpPage to navigate to your required page like below.

`_pageController.jumpToPage(3 - 1);`
Share:
3,078
Frankenstein
Author by

Frankenstein

Sr. Software Engineer who's really good at clean and efficient code. Skilled in UIKit(iOS), AppKit(macOS) and SwiftUI. Have developed and deployed apps to App Store in both Swift/Objective-C. Looking for good opportunities, if you have one ping me @ [email protected].

Updated on December 05, 2022

Comments

  • Frankenstein
    Frankenstein over 1 year

    I'm new to dart and I know this might be simple. But, I was not able to find a simple answer on, How do I enable paging in Flutter's GridView. I'm from a swift background where this can be achieved by just one line. collectionView.isPagingEnabled = true. Similarly how can I achieve this in dart?