lonewolf
lonewolf

Reputation: 81

Show one item at a time in a listView in flutter

I have a list of photos and want that one photo should be shown at a time. By this I mean if a user scrolls down then the upper photo should not be seen only the new one should be seen. It should not be like you can hold the scroll between two images. I want something like instagram reels where one reel is visible at a time.

CODE:-

              ListView.builder(
                  shrinkWrap: true,
                  itemCount: postList.length,
                  itemBuilder: (context,index)
                  {
                    return postList[index];
                  },
                );

Upvotes: 0

Views: 2217

Answers (3)

Shailendra Rajput
Shailendra Rajput

Reputation: 2982

You can use the Physics Property of Listview. use this

physics: PageScrollPhysics(),

Upvotes: 2

Shirsh Shukla
Shirsh Shukla

Reputation: 5993

its your listView

ListView.builder(
              shrinkWrap: true,
              itemCount: postList.length,
              itemBuilder: (context,index)
              {
                return postList[index];
              },
            );

You can use pageView with Scroll direction vertical,

postList(){
return PageView(
        scrollDirection: Axis.vertical,
       itemBuilder: yourPageItems...,
       itemCount: listItemCount,

}

Upvotes: 0

51v4
51v4

Reputation: 1291

You could achieve this using a PageView widget, or you could also use some plugin like tiktoklikescroller

Upvotes: 1

Related Questions