【发布时间】:2020-04-21 21:08:46
【问题描述】:
我正在尝试使用 json 在颤振中创建一个可靠的下拉列表。 我的代码中有这个 json 列表
List<Map> myJson = [
{"id": 0, "continent": "Africa", "country":"Egypt"},
{"id": 1, "continent": "Europe", "country":"Denmark"},
{"id": 2, "continent": "Asia", "country":"India"},
{"id": 3, "continent": "Africa", "country":"Kenya"},
{"id": 4, "continent": "Europe", "country":"Spain"},
];
我正在下拉列表中显示大陆
DropdownButton<String>(
isExpanded: true,
isDense: true,
hint: new Text("Select"),
value: _mySelection,
onChanged: (String newValue) {
setState(() {
_mySelection = newValue;
});
print(_mySelection);
},
items: myJson.map((Map val) {
return new DropdownMenuItem<String>(
value: val["continent"].toString(),
child: Text(
val["continent"],
),
);
}).toList(),
),
上面的代码不起作用。每当我运行它时,我都会在控制台上收到此错误。
A non-null String must be provided to a Text widget.
'package:flutter/src/widgets/text.dart':
Failed assertion: line 285 pos 10: 'data != null'
如果从当前下拉列表中选择非洲,我想显示非洲国家列表并将其填充到另一个下拉列表(例如国家下拉列表)中。我已经寻找解决方案,但堆栈溢出的大多数解决方案与我的情况无关。提前致谢。
【问题讨论】:
-
第 285 行是什么?
-
它指向一个颤振模块
-
我对 Flutter 不熟悉。它是否提供完整的堆栈跟踪来帮助您找到自己代码中的哪一行发起了导致错误的调用?
-
这是它实际上并没有指向我自己的代码的问题
标签: flutter