-
Notifications
You must be signed in to change notification settings - Fork 0
/
10. asynchronous-programming.dart
38 lines (32 loc) · 1.3 KB
/
10. asynchronous-programming.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/// Asynchronous programming in Dart
/// Asynchronous programming is a style of programming where the execution of a task is not dependent on the previous task.
/// In other words, a task is executed without blocking the main thread. In asynchronous programming, a task is executed in the background.
import 'dart:async';
void main(List<String> args) {
// downloading() {
// // Timer
// // The Timer class is used to execute a function after a specified duration.
// Timer(Duration(seconds: 5), () {
// print("The file has been downloaded.");
// });
// }
// print("Main program: Started");
// downloading();
// print("Main program: Ended");
// The Future class is used to represent a value that will be available in the future.
// The Future class has two methods:
// then() - used to execute a function when the future completes.
// catchError() - used to execute a function when the future completes with an error.
Future<String> checkLoginCredentials() {
Future<String> result = Future.delayed(Duration(seconds: 6), () {
return "Login Verified";
});
return result;
}
print("Main program: Started Activity 1");
checkLoginCredentials().then((result) {
print(result);
print('Welcome to System');
});
print("Main program: Started Activity 2");
}