Skip to content

Instantly share code, notes, and snippets.

@charlenopires
Created July 11, 2018 22:47
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 charlenopires/bd43af033339a98de40d4cef2f9df00f to your computer and use it in GitHub Desktop.
Save charlenopires/bd43af033339a98de40d4cef2f9df00f to your computer and use it in GitHub Desktop.
Example of Async/Await in Dart
import 'dart:async';
import 'dart:html';
Future main() async {
try{
final response = await HttpRequest.getString('https://rebounce.online/api/time');
print('Request was successful');
print(response);
}catch(error){
print('The request was not successful');
print(error);
}
print('Main function was ended');
// HttpRequest
// .getString('https://rebounce.online/api/time')
// .then((String response) {
// print('Request was sucessful');
// print(response);
// })
// .catchError((dynamic error){
// print('The request was not successful');
// print(error);
// });
// print('Main function was ended');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment