isNotEmpty function
Returns true
when value
is not empty or not null otherwise returns false It can check on data types like:
bool?, String?, num?, Map?, List?`
Throws UnexpectedTypeException
when other type is encountered.
Implementation
bool isNotEmpty(dynamic value) {
if (value == null) {
return false;
}
if (value is bool) {
return value;
} else if (value is String) {
return value.trim() != '';
} else if (value is num) {
return value != 0;
} else if (value is Map) {
return value.isNotEmpty;
} else if (value is List) {
return value.isNotEmpty;
}
throw throw Exception(
'Expected: `String`, `num`, `List`, `Map`, `bool`, found ${value.runtimeType.toString()}');
}