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');
}
@iqfareez
Copy link

iqfareez commented Sep 4, 2020

For VS Code user, you can run this scratch file by running dart scratch.dart in Terminal.

Result:

PS C:\Users\maple\Documents\Flutter course App Brewery\Learn-Flutter-AppBrewery\Section 13 Clima\Clima-Flutter> dart scratch.dart  
Task 1 complete
Task 2 complete
Task 3 complete
PS C:\Users\maple\Documents\Flutter course App Brewery\Learn-Flutter-AppBrewery\Section 13 Clima\Clima-Flutter>

@dvtbarton
Copy link

For VS Code user, you can run this scratch file by running dart scratch.dart in Terminal.

Result:

PS C:\Users\maple\Documents\Flutter course App Brewery\Learn-Flutter-AppBrewery\Section 13 Clima\Clima-Flutter> dart scratch.dart  
Task 1 complete
Task 2 complete
Task 3 complete
PS C:\Users\maple\Documents\Flutter course App Brewery\Learn-Flutter-AppBrewery\Section 13 Clima\Clima-Flutter>

In VS Code, you can also get the Code Runner extension by Jun Han which will let you right-click on the scratch.dart file and click "Run Code" to achieve the same thing.

@Nisarshalmani
Copy link

really a good teaching method

@yogithesymbian
Copy link

yogithesymbian commented Aug 16, 2021

For VS Code user, you can run this scratch file by running dart scratch.dart in Terminal.
Result:

PS C:\Users\maple\Documents\Flutter course App Brewery\Learn-Flutter-AppBrewery\Section 13 Clima\Clima-Flutter> dart scratch.dart  
Task 1 complete
Task 2 complete
Task 3 complete
PS C:\Users\maple\Documents\Flutter course App Brewery\Learn-Flutter-AppBrewery\Section 13 Clima\Clima-Flutter>

In VS Code, you can also get the Code Runner extension by Jun Han which will let you right-click on the scratch.dart file and click "Run Code" to achieve the same thing.

same , i have use it for run ios/android/only single file .dart . flutter2.2_scratch_completed.dart

@plh97
Copy link

plh97 commented Apr 23, 2022

good good study
day day up!

@darshan9954
Copy link

good and nice try..

@VISHALGUPTA100803
Copy link

the course is outdated it is taking lot of time to debugging null safety

@fidelmak
Copy link

fidelmak commented Jun 1, 2023

this course needs updates and re-shaping

@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