-
Notifications
You must be signed in to change notification settings - Fork 0
/
second.dart
90 lines (71 loc) · 1.62 KB
/
second.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class Employee{
int _value1; //private
int? value2 =null; //public
int _age =2;
void set Age(int ageValue){
_age = ageValue;
print("your age is $ageValue");
}
int get Age{
return _age;
}
Employee(this._value1,this.value2); //Constructor
void NullSafetyDemo(){
//Null safety
int sum = _value1 + value2!; //! null check
print(sum);
}
void ListDemo(){
List<String> names = ["subbu", "Raju", "Varma"];
var newNames = [...names,"Venky"]; // spread operator
print(newNames);
//Generators
var list =List.generate(100, (index){
return "Item $index";
});
print(list);
}
void SetDemo(){
Set<String> names = {"subbu", "Raju", "Varma","subbu"};
var newNames = {...names,"Venky"}; // spread operator
print(newNames);
}
void MapDemo(){
var names = {"FirstName":"subbu", "LastName":"Balaraju"};
var newNames = {...names,"Middle":"Raju"}; // spread operator
//Other way
/*var test = new Map();
test['FirstName'] = 'subbu';*/
print(newNames);
}
void LoopsDemo(){
List<String> names = ["subbu", "Raju", "Varma"];
for (int i = 0; i < names.length; i++) {
print("LoopsDemo : "+names[i]);
}
// for( var name in names){
// print("LoopsDemo : "+name);
// }
// names.forEach((name) {
// print("LoopsDemo : "+name);
// });
}
//Functions Demo
//Optional parameters
int square({int num = 2}){
return num*num;
}
//Arrow function
int arrowSquare(int num) => num*num;
//Anonymous Function
void AnonymousDemo(){
List<String> names = ["subbu", "Raju", "Varma"];
names.forEach((name) {
print(name);
});
names.forEach(display);
}
void display(String name){
print(name);
}
}