-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
59 lines (47 loc) · 1.17 KB
/
main.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
void main(){
dynamic a = 1;
a = 'Here\'s a string now';
print('$a');
a = 100;
print('$a');
}
void main(){
print("Hello World");
}
//THIS MAIN FUNCTION SHOWS THAT AN EXAMPLE OF SETTING A VARIABLE AS NULLABLE
// void main() {
// String? a;
// a = null;
// print('$a');
// }
//SHOWS THAT THE INT WILL GET AN ERROR ONLY BECAUSE IT ISN'T SET AS NULLABLE
// void main(){
// int a;
// a = null;
// print('$a');
// }
//THIS MAIN FUNCTION SHOWS THAT THE NULL TYPE SAFETY SYSTEM IS APPLIED TO THINGS SUCH AS LISTS TOO
//YOU HAVE TO BE CAREFUL WHERE YOU PLACE THE NULLIBLE MARKER BECAUSE THE PLACEMENT MEANS
//DIFFERENT THINGS
void main() {
List<String> aListOfStrings = ['one', 'two', 'three'];
List<String>? aNullableListOfStrings;
List<String?> aListOfNullableStrings = ['one', null, 'three'];
print('aListOfStrings is $aListOfStrings.');
print('aNullableListOfStrings is $aNullableListOfStrings.');
print('aListOfNullableStrings is $aListOfNullableStrings.');
}
void main() {
int x = 10;
int y = 20;
void printXandY() {
print(x);
print(y);
}
printXandY(); // Output: 10, 20
{
int x = 30;
int y = 40;
printXandY(); // Output: 10, 20
}
}