Flutter异步

多个任务完成后执行下一个任务
Future printUserName() async {
List results= await Future.wait([getUserName(),getUserAge()]);
print('my name is :{results[1]} years old');
}

Future getUserName() =>
Future.delayed(Duration(seconds: 1), () => 'ShuSheng007');
Future getUserAge() =>
Future.delayed(Duration(seconds: 2), () => 18);

你可能感兴趣的:(Flutter异步)