phongyewtong
phongyewtong

Reputation: 5319

how to get flutter future.wait response?

how to get flutter future.wait response??? i have done a casting but it still doesn't work.

error:

[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

code:

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>>;
}

Upvotes: 1

Views: 844

Answers (1)

phongyewtong
phongyewtong

Reputation: 5319

here is the correct answer. added an await in front of future.await and remove the future from 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())
    ]);
}

Upvotes: 1

Related Questions