【发布时间】:2022-01-08 18:42:28
【问题描述】:
我正在尝试使用 http mathod“GET”从实时数据库中获取测验数据。 正在检索数据,但它没有显示在 listview 中,当我打印列表的长度时,它为 0。这就是我的终端中显示的错误:错误:预期类型为“int”的值,但得到了“字符串”类型之一
我无法弄清楚问题是什么。请帮我解决这个问题,因为我尝试了大约 5 天但无法解决。
谢谢。
这些是我在列表中获取数据的代码。
Future<void> getList() async {
list.clear();
final url = Uri.parse(
'https://testisnotesttheisthelearningapp-default-rtdb.firebaseio.com/Schools/${widget.uid}/ResultsFolder/${widget.id}.json');
final response = await get(url);
print(response.body);
var map = json.decode(response.body) as Map<String, dynamic>;
// print(map);
if (map != null) {
map.forEach((key, value) {
print(value['Name']);
var temp = Result(
value['Percent'],
(value['choice'] as List<dynamic>)
.map((e) => Model(e['index'], e['question'], []))
.toList(),
value['Score'],
(value['question'] as List<dynamic>).map((e) => e).toList(),
value['Name']);
list.add(temp);
});
}
}
这是我的实时数据库中的 JSON 格式数据:
{
"Name" : "Miets Digital",
"Percent" : 100,
"Score" : 2,
"choice" : [ "Correct", "Correct" ],
"question" : [ {
"question" : "WHo is Elon Musk?"
}, {
"question" : "How did Elon musk got rich?"
} ]
}
【问题讨论】:
标签: firebase flutter http listview firebase-realtime-database