【发布时间】:2021-11-13 08:39:13
【问题描述】:
示例代码
Map<String,String> gg={'gg':'abc','kk':'kojk'};
Future<void> secondAsync() async {
await Future.delayed(const Duration(seconds: 2));
print("Second!");
gg.forEach((key,value) async{await Future.delayed(const Duration(seconds: 5));
print("Third!");
});
}
Future<void> thirdAsync() async {
await Future<String>.delayed(const Duration(seconds: 2));
print('third');
}
void main() async {
secondAsync().then((_){thirdAsync();});
}
输出
Second!
third
Third!
Third!
如您所见,我想用等到地图的 foreach 循环完成然后我想打印 third
预期输出
Second!
Third!
Third!
third
【问题讨论】:
标签: flutter dart asynchronous callback