I created two function. I want that, at first complete the count() function and then run text() function. But isn’t not working. Where is the problem ?
Future<void> count() async {
for (var i = 1; i <= 10; i++) {
Future.delayed(Duration(seconds: i), () => print(i));
}
}
Future<void> text() async{
print("Done");
}
void main() {
count().then((value) {
text();
});
}
>Solution :
You have to await the Future.delayed and you also need to change the Duration to 1 second:
Future<void> count() async {
for (var i = 1; i <= 10; i++) {
await Future.delayed(Duration(seconds: 1), () => print(i));
}
}
Future<void> text() async{
print("Done");
}
void main() async {
count().then((value) {
text();
});
}