Flutter: How to scroll listview on next and previous button click?

Adarsh Chauhan
2 min readDec 28, 2021

We all know how to access specific index in Listview. But, We often see that the movies list is displayed horizontally in applications like Netflix, Hotstar. And Items can go back and forth at the click of a button. I want to show you how we can do this.

How to scroll listview items using next and previous button?

We will also check how to count the ListView items that are on the screen.

And for this we have to use scrollable_positioned_list dependency.

scrollable_positioned_list contains builder method or separated method. And in this example we’ll use separated method to build the list of widgets.

Before we proceed further, we should know about the itemScrollController and itemPositionsListener.

ItemScrollController: Controller for jumping or scrolling to an item.

ItemPositionsListener: Create a [ScrollablePositionedList] whose items are provided by [itemBuilder] and separators provided by [separatorBuilder].

Use Dependency:

scrollable_positioned_list: ^0.2.3

Example: Generate the list of sixteen items and will see or count the onScreen items of list and will tap on next button icon to move next item on screen and will tap on previous button icon to move previous item back to the screen.

So lets start :)

Code Snippet:

OutPut:

here is the output.

That’s all Thank You :)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Adarsh Chauhan
Adarsh Chauhan

Written by Adarsh Chauhan

🚀 Flutter Developer | UI/UX Design Enthusiast | Sharing Art of Flutter

No responses yet

Write a response