void checkString(String str) {
if (str.isEmpty) {
print('String is empty');
} else {
print('String is not empty');
}
}
void main() {
checkString('');
// -> String is empty
checkString('hello');
// -> String is not empty
}
Explanation of the above code example
Check if values are null, empty, false using List.contains() function
void checkString(value) {
if (['', null, 0, false].contains(value)) {
print('Value is falsey');
} else {
print('Value is OK');
}
}
void main() {
checkString('');
// -> Value is falsey
checkString(null);
// -> Value is falsey
checkString(false);
// -> Value is falsey
checkString('hello');
// -> Value is OK
checkString(0);
// -> Value is falsey
}
0 Comments