[英]The method '>' was called on null. Receiver: null Tried calling: >(1e-10) The relevant error-causing widget was Column
I was writing this piece of code:我正在写这段代码:
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'),
],
),
],
),
I wanted to make a scrollable grid with a scrollable list under that, but I want to make sure that if I scroll the grid the list isn't scrolled and vice versa.我想制作一个带有可滚动列表的可滚动网格,但我想确保如果我滚动网格,列表不会滚动,反之亦然。 The code above doesn't work.
上面的代码不起作用。 Does anyone know why?
有谁知道为什么? I'm still a newbie in Flutter and I'm trying to learn it.
我仍然是 Flutter 的新手,我正在努力学习它。
just use method to create list of inkWell
s and call it as children of the GridView.只需使用方法创建
inkWell
的列表并将其称为 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;
}
You missed square brackets
after for statement.您在 for 语句后错过了
square brackets
。
If you need to recap how to use for
in a widget tree take a look here How to use a "for" loop inside children of a widget?如果您需要回顾如何在小部件树中使用
for
,请查看此处如何在小部件的子级中使用“for”循环?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.