[英]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
,它呈现一个容器列表,当用户单击它时可以扩展高度(我使用 AnimatedSize 来包装容器),但是我注意到当容器扩展时我无法滚动ListView 通过在扩展区域周围按住并拖动,仅在 Container 最初占用的区域内。
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.用SingleChildScrollView
包装该Listview
并将physics: NeverScrollableScrollPhysics()
添加到Listview
并检查。
Try to wrap your ListView.builder
in a ConstrainedBox
.尝试将ListView.builder
包装在ConstrainedBox
中。
ConstrainedBox(
constraints: BoxConstraints(minHeight: constraint.maxHeight),
child: 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);
});
},
),
),
So I found my problem is that my list item had a GridView
widget, I changed the physics to NeverScroll and fixed it.所以我发现我的问题是我的列表项有一个GridView
小部件,我将物理更改为 NeverScroll 并修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.