-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path022_null_safety.dart
72 lines (58 loc) · 1.31 KB
/
022_null_safety.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
// Null safety olmadan
bool isEmpty(String string) => string.length == 0;
// isEmpty(null);
// Using null safety:
void makeCoffee(String coffee, [String? dairy]) {
if (dairy != null) {
print('$coffee with $dairy');
} else {
print('Black $coffee');
}
}
// Geçersiz turlerin kullanımı
// Hypothetical unsound null safety:
bad(String? maybeString) {
// print(maybeString.length); // HATA
}
void foo1() {
makeCoffee("coffee", "milk");
}
void foo2() {
bad(null);
}
// Hypothetical unsound null safety:
requireStringNotNull(String definitelyString) {
print(definitelyString.length);
}
void foo3() {
// ignore: unused_local_variable
String? maybeString = null; // Or not!
// requireStringNotNull(maybeString); //! HATA : NULLABLE
}
// bool isEmptyList([Object? object]) {
// return (object is List) ? object.isEmpty : false;
// }
bool isEmptyList(Object object) {
if (object is! List) return false;
return object.isEmpty;
}
void foo4() {
print(isEmptyList([]));
print(isEmptyList(42));
}
void foo5() {
String? notAString = null;
print(notAString?.length);
}
/// null safety olmadan kullanımı
///
/// void foo6() {
/// String? notAString = null;
/// print(notAString.length);
/// }
///
void foo6() {
String? notAString = null;
print(notAString!.length);
}
void main() => foo5();