简体   繁体   English

当孩子扩展高度时无法滚动 ListView

[英]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.

相关问题 使用单个子滚动视图时使字母滚动列表视图高度动态导致滚动时出现列表问题 - Making the Alphabet scroll listview height dynamic when using the single child scroll view causing issue for list while scroll 使用 2 ListView.builder 时无法正确滚动 - Can't scroll properly when using 2 ListView.builder 无法滚动列表视图内容 - Can't scroll listview contents 行高扩展时,将图标置于底部 - Position icon at bottom when row height expands Flutter - 无法滚动到 listView 的底部 - Flutter - can't scroll to the bottom of listView 当滚动方向为水平时,如何显示设置的 ListView 的中间孩子? - How to show the set middle child of ListView when scroll Direction is horizontal? 当我滚动子 ListView Flutter 时,InviewNotifierList(父级)正在重建 - InviewNotifierList (Parent) is getting rebuild when I scroll Child ListView Flutter Flutter:ListView:当子 ListView 到达底部时滚动父 ListView - ClampingScrollPhysics 在大小容器中不起作用 - Flutter : ListView : Scroll parent ListView when child ListView reach bottom - ClampingScrollPhysics not working in sized container 当子 ListView 达到滚动限制时让 PageView 页面滚动 - 嵌套滚动? - Make PageView page scroll when child ListView reaches scroll limit - nested scroll? 在顶部添加新项目时无法在 ListView 中保持滚动位置 - Can't keep scroll position in ListView when adding new item on top
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM