-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtips_tricks.dart
54 lines (47 loc) · 1.58 KB
/
tips_tricks.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
void main() {
/*String repeat =
"lal kumar pun" * 5; //used on testing purpose for many dummy datas
print(repeat); */ // This is string multiplications
// store();
SpreadOperator();
}
//--------------------Use of future keywords with async and await keywords-----------------------------------
/* void store() async {
//async and await used during using of future only
var data = await downloads();
print(data);
}
Future<String> downloads() {
var result = Future.delayed(Duration(seconds: 3), () {
return "hello future code works dear lal for async and await";
});
return result;
} */
/* -----------------------Use of future keywords with then keywords-----------------------------------
// using then keyword have feautures of error in dart languages than that of await and async
void store() {
// Future<String> data = downloads(); neeeds in future
var data = downloads(); // needs immediatley
data.then((response) => print(response), onError: (Error) {
print(Error);
});
}
Future<String> downloads() {
Future<String> result = Future.delayed(Duration(seconds: 3), () {
return Future.error("hello error for then keywords");
});
return result;
}*/
//-------------------SPREAD OPERATOR-------------------------------------------------------------------
void SpreadOperator() {
var marks = 30;
//-----------------IF ELSE shortcut
// bool ifElseShorcut = true;
// ifElseShorcut ? "its true condition" : "else false condition";
List<String> std = [
"lal",
if (marks > 40) ...["not match"],
if (marks > 20) ...["match"]
];
print(std);
}