首页 > 解决方案 > 扑动 StaggerGridView 与 ListView 的孩子完全显示

问题描述

如何在网格中的每个项目中使用 ListView 的子项编写 StaggerGridView。我目前对此进行了实施:

StaggeredGridView.countBuilder(
              physics: BouncingScrollPhysics(),
              padding: EdgeInsets.symmetric(horizontal: 4, vertical: 0),
              crossAxisCount: 4,
              itemCount: _data.length,
              itemBuilder: (BuildContext context, int index) {
                print(index);
                Project p = _data[index].keys.elementAt(0);
                List<Tasks> _ts = _data[index].values.expand((l) => l).toList();
                return Padding(
                    padding: EdgeInsets.symmetric(horizontal: 2, vertical: 6),
                    child: PhysicalModel(
                        borderRadius: BorderRadius.circular(16),
                        // shape: ,
                        shadowColor: Colors.grey.withAlpha(10),
                        elevation: 6,
                        color: Colors.transparent,
                        child: Ink(
                            padding: EdgeInsets.symmetric(
                                horizontal: 0, vertical: 6),
                            color: Theme.of(context).scaffoldBackgroundColor,
                            // color: Colors.white,
                            child: ListView.builder(
                                itemCount: _ts.length + 1,
                                // physics: NeverScrollableScrollPhysics(),
                                itemBuilder: (BuildContext context, int idx) {
                                  if (idx == 0) {
                                    return Padding(
                                        padding: EdgeInsets.only(
                                            left: 12, bottom: 12, top: 8),
                                        child: Row(
                                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text(
                                              getProjectNameFirstName(p.name),
                                              style: NORMAL_BOLD_TXT_STYLE
                                                  .copyWith(
                                                      fontSize: 22,
                                                      color: COLOR_PRIMARY),
                                            ),
                                            // SizedBox(width: 8),
                                            Container(
                                              padding: EdgeInsets.symmetric(
                                                  horizontal: 4, vertical: 1),
                                              decoration: BoxDecoration(
                                                  color: Color(p.colorValue)
                                                      .withAlpha(100),
                                                  borderRadius:
                                                      BorderRadius.circular(5),
                                                 ),
                                              child: Text(
                                                getProjectNameRealName(p.name),
                                                style: SMALL_TXT_STYLE
                                                    .copyWith(
                                                        color: Color(p.colorValue)),
                                              ),
                                            )
                                          ],
                                        ));
                                  } else {
                                    // index = index - 1;
                                    print(idx);
                                    Tasks _t = _ts[idx - 1];
                                    return ListTile();)));

这只是我的示例代码。目前的问题是由于 listview 是动态的,gridview 项目的高度不能显示所有 listview 项目

有没有办法显示所有列表视图项目并使其成为 NeverScrollPhysics?

标签: flutter

解决方案


我正在疯狂猜测您要在这里实现的目标;如果您可以更详细地解释您要实现的目标,而不是为什么您的特定实现不起作用,那将很有帮助,因为这样有人可能会提出解决整体问题的方法。

猜测如下:

  1. 你有一个交错的网格视图,每个视图都有一个项目列表
  2. 你想在gridview的每个元素中显示一个完整的列表
  3. 使用 listviews 不起作用,因为它没有显示整个列表,而是滚动(和/或有错误)

首先,有什么理由不能使用 Column/Row/Flex 而不是 ListView?由于 Column/Row/Flex 较新滚动,这应该可以解决该问题。

如果这不可能,理论上您可以在 ListView 上将 shrinkWrap 设置为 true。


推荐阅读