Skip to content

Instantly share code, notes, and snippets.

@yishingene
Last active June 1, 2019 15:27
Show Gist options
  • Select an option

  • Save yishingene/a579a8ae735a78c3992ecd92312cf313 to your computer and use it in GitHub Desktop.

Select an option

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
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