Cant scroll with ListView.builder() - flutter

I was wondering if anyone had an issue where they use a ListView.builder() and then it doesn't want to scroll
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: widget.product.category.length,
itemBuilder: (context, index) {
final item = widget.product.category[index];
return ListTile(title: Text(item));
},
)

I'd suggest you do the following:
Remove shrinkWrap and make sure the value passed to itemCount is large enough to make the widget scroll.
If you place the list view inside a vertically scrolling list, it's not going to scroll... In this case, you should probably be using slivers

Related

How ListView can Stop at each element in Flutter

My question is very simple but I did not find a result.
In a ListView.builder (with horizontal scroll) for example if there are 5 elements the user can scroll them all at once. I would like that the user can scroll only 1 by 1.
In short I would like the animation of the list to stop at each element.
Example of my list :
Widget _list()
{
return ListView.builder(
physics: const ClampingScrollPhysics(),
scrollDirection: _horizontalDisplay? Axis.horizontal : Axis.vertical,
itemCount: data!.length,
itemBuilder: (context, index)
{
return widgetToDisplay(index);
}
);
}
The ListView.builder can't make it, you need to use carousel_slider package

Can't scroll ListView when child expands height

I have a ListView.builder that renders a list of Containers who can expand in height when the user clicks on it ( I'm using AnimatedSize to wrap the Containers), however I noticed that when the Container is expanded I can't scroll the ListView by pressing and dragging around the expanded area, only in the area that Container occupied originally.
ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
itemCount: profilesList.profilesCount,
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return ProfileBar(
id: profilesList.profiles[index].id!,
index: index,
name: profilesList.profiles[index].name,
emoji: profilesList.profiles[index].emoji,
gender: profilesList.profiles[index].gender,
color: profilesList.profiles[index].color,
height: profilesList.profiles[index].height,
birthday: profilesList.profiles[index].birthday,
isSelected: profilesList.selectedProfileID ==
profilesList.profiles[index].id,
onSelect: (_) async {
profilesList.selectProfile(
profilesList.profiles[index].id!);
Provider.of<GoalModel>(context, listen: false).getGoal(profilesList.profiles[index].id!);
await UserSettings.setProfile(
profilesList.profiles[index].id!);
_getRecords(context);
});
},
),
Is there a way to fix this?
Wrap that Listview with SingleChildScrollView and add physics : NeverScrollableScrollPhysics() to Listview and check.
So I found my problem is that my list item had a GridView widget, I changed the physics to NeverScroll and fixed it.

Flutter Nested Listviews design float up when content grows

there I have 3 nested listview. Here is it's representation.
(Items, titles, subtitles are nested listview builder)
In default, title and leading icon is aligned to each other. Title's subtitles are also another list view. As you can see when my title has only one subtitle there is no problem. But if you look item 3 it has 3 subtitle so it's going to up. And my top padding change also my leading icon and my title are not aligned anymore.
My listview builders main representation:
child: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
...
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: items.titles.length,
itemBuilder: (context, titleInd) {
.........
child: ListTile(
.....
subtitle: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,)
....
),
}
Couldn't find the reason that effect my paddings and leading icon-title alignment. What can be reason of that and How can I fix this issue?

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];
},
);
You can use the Physics Property of Listview. use this
physics: PageScrollPhysics(),
You could achieve this using a PageView widget, or you could also use some plugin like tiktoklikescroller
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,
}

Flutter How to vertical scroll a screen like a book

e-book
I want to make an e-book with scrolling screens that are images with Flutter
You should use PageView. Using page view you can either scroll page horizontally or vertically.
PageView.builder(
itemBuilder: (context, position) {
return _buildPage();
},
itemCount: listItemCount,
scrollDirection: Axis.vertical,
)