flutter - 如何在 Flutter 中为所有设备制作网格视图?
问题描述
我的应用程序中有一个带有图像和文本的常规 GridView。我最近使用设备预览来查看它在其他设备上的显示方式,它在平板电脑和小型手机上的显示方式非常不同。是否可以在所有设备上制作一个间距均匀的单个网格,以使其差异不大?这是我的代码:
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 15.0,
crossAxisSpacing: 10.0,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.92),
),
itemCount: 100,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
child: GridTile(
child: Image.network(
'https://lh3.googleusercontent.com/proxy/DC95dZwFErJk5toYcgiDngZbOnQuvHsZHMe7hIUol_dlykLi3xgJljZlljxJJU2WM2jACnOpHXjidqamjHWIOQ6DrABhkXahUzKwQSIC9dXPGJb8NhqJiLxRNcEEQseKAH9DlEHYgBEsMtY8pqubmv3HU2L15i5CJyuGs5XFhw',
height: 150,
fit: BoxFit.fill,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 2.0),
child: RichText(
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
maxLines: 1,
text: TextSpan(
text: 'Hello',
style: kTasksStyle.copyWith(
color: kDarkBlue,
fontSize: getValueForScreenType<double>(
context: context, mobile: 14, tablet: 20),
),
),
)),
],
);
},
),
解决方案
如果我误解了您的问题或您需要澄清,请纠正我。
我认为你的问题是由于你没有使用媒体查询,mainAxisSpacing
所以crossAxisSpacing
你使用的设备越大,网格项目之间的空间就越大。您似乎也对Text
.
推荐阅读
- css - CSS:如何选择一个元素是其中一个祖先(不是直接父)的第一个类型?
- c++ - 具有第二种模板类型的部分模板特化
- python - 为 Discord 排行榜排序 JSON 文件
- python - 如何在 Python 中生成月份名称作为列表?
- ffmpeg - 当多个循环输入缓冲区中的任何一个溢出时如何使ffmpeg失败
- amazon-web-services - nginx 入口控制器显示在 AWS EKS 中运行,但运行状况检查显示 OutOfService
- function - Go - exec.Command() 但对于字符串切片
- api - 工件 REST API 归档条目列表
- python - 如何加密和解密电子邮件地址以匿名数据
- c# - 值 0 (int32) 的 CIL 指令“isinst [System.Runtime]System.Int32” - 将返回什么?