flutter 在抖动中水平居中网格视图或列表视图的最后一个奇数项

rjee0c15  于 2023-01-31  发布在  Flutter
关注(0)|答案(1)|浏览(137)

将网格视图或列表视图的最后一个奇数项水平居中
我试过staggeredGridView,但它没有对齐。

r1zk6ea1

r1zk6ea11#

请尝试以下代码:

SizedBox(
                  height: h * 0.4,
                  child: StaggeredGridView.countBuilder(
                    crossAxisCount: 3,
                    itemCount: 7,
                    itemBuilder: (BuildContext context, int index) => Container(
                        child: Center(
                      child: Container(
                        height: w / 4,
                        width: w / 4,
                        decoration: const BoxDecoration(
                          color: Colors.green,
                          borderRadius: BorderRadius.all(Radius.circular(10)),
                        ),
                        child: Center(
                          child: Text(
                            index == 6 ? "C" : "$index",
                            style: const TextStyle(
                                fontSize: 20, fontWeight: FontWeight.bold),
                          ),
                        ),
                      ),
                    )),
                    staggeredTileBuilder: (int index) =>
                        StaggeredTile.count(index == 6 ? 3 : 1, 1),
                  ),
                ),

相关问题