Basic Concept of Asynchronous programming
Last updated
Last updated
void main() {
// Synchronous Code
print("test1");
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
testfunction();
print("test3");
}
void testfunction(){
print("test2");
}void main() {
// Futures
print(" Start fetching images");
getData();
print("Loading Images");
}
void getData() {
//callback
Future.delayed(Duration(seconds: 5), () {
// Logic
print(" Image Fetched !!!!!");
});
}
import "dart:html";
void main() {
// Futures
print("A");
var result =
HttpRequest.getString('https://jsonplaceholder.typicode.com/todos/1');
print(result);
print("B");
}