Dart Future.wait for multiple futures and get back results of different types

后端 未结 3 763
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 18:03

I\'m using Flutter to download 3 different sets of data from a server, then do something with all 3 sets. I could do this:

List foos = await downl         


        
3条回答
  •  终归单人心
    2021-01-18 18:45

    Well, type T is a generic type

    You know your types, so you can work with them.

    If your are using a FutureBuilder, you can access the different results using this. (same order you put them in the Future.wait method)

    snapshot.data[0] // maybe type List
    snapshot.data[1] // maybe type List
    snapshot.data[2] // maybe type String
    

提交回复
热议问题