flutter - 在 Flutter 中使用 StaggeredGridView 时,有没有办法优化布局以最小化空白?
问题描述
如何最小化网格中的空白?
在我的示例网格中,我有三个瓦片,但正如您所见,在 0 号瓦片旁边有很多空白。这个空间可以用 2 号瓦片填充以减少总空白。
我怎样才能做到这一点?
@override
Widget build(BuildContext context) {
return new StaggeredGridView.countBuilder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
itemCount: payback.keys.length,
itemBuilder: (BuildContext context, int index) {
if (index.isEven) {
return Container(color: Colors.green, width: 100, height: 100, child: Center(child:Text(index.toString(), textScaleFactor: 4, style: TextStyle(color: Colors.white),)));
} else {
return Container(color: Colors.green, width: 200, height: 200, child: Center(child:Text(index.toString(), textScaleFactor: 4, style: TextStyle(color: Colors.white),)));
}
},
staggeredTileBuilder: (int index) {
if (index.isEven) {
return StaggeredTile.fit(1);
} else {
return StaggeredTile.fit(2);
}
},
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
);
解决方案
推荐阅读
- javascript - 是否可以使用 nodemailer 将回复字段设置为 cc?
- azure-devops - Azure DevOps YAML 构建管道 - 设置脚本任务名称
- laravel - 如何将小部件日期包颤动的日期数据发布到数据库?
- c# - 将值从 URL 参数传输到 asp:TextField
- android - 如果我单击主菜单工具的任何选项,我的 android studio 没有响应
- c# - 在列表 C# 中动态存储多个枚举
- android - MediaRecoder.stop() 耗时过长
- html - 从网络服务器检索 URL/href 到 ESP8266(处理它)
- amazon-web-services - AWS (S3) - Github - Vue:根据更改的分支触发构建
- python - 如何在 SQL Alchemy 中仅将 Python 表达式用作混合属性