Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created July 6, 2019 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlid/f8d59c5c08f8805c5169bdb644a2da2c to your computer and use it in GitHub Desktop.
Save ryanlid/f8d59c5c08f8805c5169bdb644a2da2c to your computer and use it in GitHub Desktop.
dart async await Future (flutter)
import 'dart:io';
void main() {
performTask();
}
void performTask() async {
task1();
String task2result = await task2();
task3(task2result);
}
void task1() {
print('task 1 complete');
}
Future task2() async {
Duration threeSeconds = Duration(seconds: 3);
String result;
await Future.delayed(threeSeconds, () {
result = 'task 2 data';
print('task 2 complete');
});
return result;
}
void task3(String task2Data) {
String result = 'task 3 data';
print('task 3 complete $task2Data');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment