如何使未来动荡。等待响应???我已经进行了投射,但仍然无法正常工作。
错误:
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: type 'Future<List<Map<String, dynamic>>>' is not a subtype of type 'List<Map<String, dynamic>>' in type cast
代码:
Future<void> addNewTask(User data, [BuildContext context]) async {
Future<List<Map<String, dynamic>>> responses = Future.wait([
Database.addUser(uid, data.toMap()),
Database.addSetting(uid, data.toMap())
]);
List<Map<String, dynamic>> firstResponse = responses as List<Map<String, dynamic>>;
}
答案 0 :(得分:1)
这是正确的答案。在future.await
前面添加了一个等待,并从List<Map<String, dynamic>>
删除了未来
Future<void> addNewTask(User data, [BuildContext context]) async {
List<Map<String, dynamic>> responses = await Future.wait([
Database.addUser(uid, data.toMap()),
Database.addSetting(uid, data.toMap())
]);
}