Skip to content

Instantly share code, notes, and snippets.

@angelabauer
Created April 6, 2019 15:50
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save angelabauer/c19c42b7795a185d2113f3b47263d2c0 to your computer and use it in GitHub Desktop.
Save angelabauer/c19c42b7795a185d2113f3b47263d2c0 to your computer and use it in GitHub Desktop.
Starting Code for Futures/Async/Await Demo
import 'dart:io';
void main() {
performTasks();
}
void performTasks() {
task1();
task2();
task3();
}
void task1() {
String result = 'task 1 data';
print('Task 1 complete');
}
void task2() {
String result = 'task 2 data';
print('Task 2 complete');
}
void task3() {
String result = 'task 3 data';
print('Task 3 complete');
}
@jumainahkhan
Copy link

not working because of null safety

@portgasalif
Copy link

portgasalif commented Aug 28, 2023

just need to add : late on

Future task2() async {
Duration threeSeconds = Duration(seconds: 3);
late String result;

await Future.delayed(threeSeconds, () {
result = 'task 2 data';
print('Task 2 complete');
});
return result;
}

result =
Task 1 complete
Task 2 complete
Task 3 complete with task 2 data

Process finished with exit code 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment