![](/img/trans.png)
[英]The getter 'length' was called on null. Receiver: null Tried calling: length. The relevant error-causing widget was: /bottom_bar.dart:17:64
[英]The method '>' was called on null. Receiver: null Tried calling: >(1e-10) The relevant error-causing widget was 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
的列表並將其稱為 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;
}
您在 for 語句后錯過了square brackets
。
如果您需要回顧如何在小部件樹中使用for
,請查看此處如何在小部件的子級中使用“for”循環?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.