Last active
June 1, 2019 15:27
-
-
Save yishingene/a579a8ae735a78c3992ecd92312cf313 to your computer and use it in GitHub Desktop.
Future implemented in Dart , print something first, then show get function completed message after 3 seconds by using future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| main(){ | |
| print('about to fetch data!'); | |
| get('http://www.google.com').then( | |
| (result){ | |
| print(result); | |
| }); // hook .then() function to get() , to implement Future | |
| } | |
| Future<String> get(String url){ | |
| return new Future.delayed( | |
| new Duration(seconds:3),(){ | |
| return 'Got the data! after 3 seconds'; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment