flutter - 在 null 上调用了方法“>”。Receiver: null 尝试调用:>(1e-10) 相关的导致错误的小部件是 Column
问题描述
我正在写这段代码:
Column(
children: <Widget>[
GridView.count(
crossAxisSpacing: 10,
mainAxisSpacing: 1,
crossAxisCount: 7,
children: <Widget>[
for (int c = 0; c < 10 /*0000*/; c++)
InkWell(
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: dateColors[c],
),
child: setDay(c),
),
onTap: () {
setState(() {
changeColors(c);
});
},
),
],
),
ListView(
shrinkWrap: true,
children: <Widget>[
Text("I'm dedicating every day to you"),
Text('Domestic life was never quite my style'),
Text('When you smile, you knock me out, I fall apart'),
Text('And I thought I was so smart'),
],
),
],
),
我想制作一个带有可滚动列表的可滚动网格,但我想确保如果我滚动网格,列表不会滚动,反之亦然。上面的代码不起作用。有谁知道为什么?我仍然是 Flutter 的新手,我正在努力学习它。
解决方案
只需使用方法创建inkWell
s 列表并将其称为 GridView 的子项。
Column(
children: <Widget>[
GridView.count(
crossAxisSpacing: 10,
mainAxisSpacing: 1,
crossAxisCount: 7,
children: _createInkWellWidgets(),
),
ListView(
shrinkWrap: true,
children: <Widget>[
Text("I'm dedicating every day to you"),
Text('Domestic life was never quite my style'),
Text('When you smile, you knock me out, I fall apart'),
Text('And I thought I was so smart'),
],
),
],
)
List<Widget> _createInkWellWidgets() {
List<Widget> widgets = [];
for (int c = 0; c < 10; c++) {
widgets.add(InkWell(
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: dateColors[c],
),
child: setDay(c),
),
onTap: () {
setState(() {
changeColors(c);
});
},
));
}
return widgets;
}
推荐阅读
- python - 如何将列分隔符添加到 Pandas 数据框显示
- python - 不同模型的训练精度不同,但测试精度相同
- spring-boot - 如何处理 Elasticsearchn CRUD 操作的负 JUNIT 测试用例
- python - 如何在python中打印出txt文件的字典值的完整列表
- docker - 解决命令在 pod Kubernetes 中以退出代码 137 终止
- regex - 在 Python 中通过多个分隔符将一列拆分为两列
- sql - 如何以编程方式在 SQL LIKE 中转义通配符?
- python - 使用快速傅里叶变换的 3d 振动数据
- java - 使用 XMLHolder 解析 XML 文件,然后将它们添加到 arrayList
- amazon-web-services - 如何将输入传递给 CloudFormation 中 StepFunction 目标的 EventRule?