Created
July 11, 2018 22:47
-
-
Save charlenopires/bd43af033339a98de40d4cef2f9df00f to your computer and use it in GitHub Desktop.
Example of Async/Await in Dart
This file contains 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'; | |
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