for example:
void main() {
List<String> list = ['1', '2', '3', '4'];
gogo(list);
print('main end');
}
void gogo(List list) async {
list.forEach((element) async {
await pS(element);
});
print('gogo end');
}
Future pS(String s) async {
Future.delayed(Duration(seconds: 1), () {
print(s);
});
}
will output:
gogo end main end 1 2 3 4
The result I am looking forward to:
1 2 3 4 gogo end main end