在Dartlang / Flutter中,我尝试使用.map()
和.toList()
创建地图列表,但收到上述错误消息。我尝试在各个地方添加类型注释,但它们只是引起了类似但不同的类型错误。
这是响应正文。
Response body: {"data":{"logsread":[{"id":"7a2dd3b","email":"email@gmail.com"}]}}
这是代码。
http.post(url, body: read2).then((response) {
print("Response status: ${response.statusCode}");
print("Response body: ${response.body}");
var tempTodos;
tempTodos = jsonDecode(response.body)['data']['logsread']
.map((node) => {
'id': 0,
'title': node['email'],
'score': 0,
})
.toList();
return Upd(model.copyWith(todoList: tempTodos));
模型类定义如下:
class Model {
final String todo;
final List<String> todos;
final Map todoWithScore;
final List<Map> todoList;
Model(this.todo, this.todos, this.todoWithScore, this.todoList);
Model copyWith({
String todo,
List<String> todos,
Map todoWithScore,
List<Map> todoList,
}) =>
Model(
todo ?? this.todo,
todos ?? this.todos,
todoWithScore ?? this.todoWithScore,
todoList ?? this.todoList,
);
}
答案 0 :(得分:0)
在添加“作为列表”之后尝试,如下所示。
{{1}}