flutter - 如何在 Flutter 中实现动态 GridView?
问题描述
我想使用SliverGridDelegateWithMaxCrossAxisExtent
, this 而不是SliverGridDelegateWithFixedCrossAxisCount
,但是当我这样做时,GridView.builder
什么也不显示。
我的问题SliverGridDelegateWithFixedCrossAxisCount
是它使用固定数量的空间,即使实际上没有任何东西可以占用它。
这是我现在的代码:
GridView.builder(
shrinkWrap: true,
itemCount: someDynamicValueRightHere, // from hive db
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
),
itemBuilder: (ctx, index) => Card(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Align(
alignment: Alignment.topRight,
child: OptionsMenu(
index: index,
),
),
Text(
'foo',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color:
Theme.of(context).textTheme.bodyText1!.color,
),
),
const SizedBox(
height: 20,
),
Text(
'foo',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color:
Theme.of(context).textTheme.bodyText1!.color,
),
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () =>foo()
),
IconButton(
onPressed: () =>
foo(),
)
],
)
],
),
),
),
),
我该如何使用SliverGridDelegateWithMaxCrossAxisExtent
?这似乎是我最好的选择,但当我这样做时,屏幕上什么也没有显示。请帮忙 !
解决方案
推荐阅读
- python - 如何通过 python 与 ftdi f232rl 模块正确通信?
- sas - 如何在 sas 企业指南中开发配置文件?
- sql - 主查询列中的 SQL 查询子表
- php - 为什么 modal 不能与 PHP 一起用于 show 几句话
- c# - 如何使用 2D 数组 C# 将结果放入表中
- javascript - 万事达卡卡号范围的正则表达式
- node.js - 如何验证 Markdown 代码以防止 XSS 攻击?
- python - 如何用 100 个随机数填写您的列表
- python - 嵌套 for 循环以使用列表理解填充数组
- c++ - fgets 无法在 Ubuntu 20.04 上从管道读取两次