flutter - 颤振我正在使用gridview.count,但我无法设置高度
问题描述
我正在使用 GridView.count 和 list.generate。
我想设置图像的高度。
我尝试在需要的地方设置高度,但没有变化
看来我的代码很愚蠢。
这是一个低层次的问题,但如果你能回答它,我将不胜感激:)
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Container(
height: MediaQuery.of(context).size.height,
child: GridView.count(
mainAxisSpacing: 5.0,
crossAxisSpacing: 5.0,
crossAxisCount: 3,
children: List.generate(
snapshot.data!.length,
(index) => ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: snapshot.data![index].posterPath.isEmpty
? Container()
: CachedNetworkImage(
fit: BoxFit.cover,
imageUrl:
'https://image.tmdb.org/t/p/original/${snapshot.data![index].posterPath}',
),
),
),
),
),
);
解决方案
尝试childAspectRatio
使用GridView
.
它是一个比率width / height
。
// As tall as it is wide
childAspectRatio:1
// 3 parts width for 2 parts height (1.5 times wider than it is tall)
childAspectRatio:3/2
// 1 part width for 2 parts height (2 times taller than it is wide)
childAspectRatio: 1/2
推荐阅读
- ssl - 如何设置 Gatling 以使用每个虚拟用户的客户端证书?
- python - 程序输出与公式不符(概率问题)
- r - 使用 Google Cloud Scheduler 在 Cloud Run 上运行 Docker 容器时出现 404 错误
- datetime - 如何将 SAS 时间值更改为日期时间值?
- javascript - 如何消除额外的uid出现在firebase push中
- python - 我可以更改从 Django 中的父类继承的字段的详细名称吗?
- python - 泡菜文件保存在本地系统的什么位置?以及如何调用和共享文件给其他用户?
- python - cartopy.crs.Geodetic 的经度范围
- google-cloud-platform - 在 Apple Silicon / Big Sur 上安装 Google Cloud SDK 时出现 anthoscli 错误
- linux - 在docker镜像“centos/python-36-centos7”中运行yum install时如何找到http url