isEmpty static method
判断一个变量是否为空,例如:null、''、[]、{}
checkNum - 若为true,则判断数字是否为0 checkString - 若为true,则判断字符串是否为 'null'
Implementation
static bool isEmpty(dynamic value, {bool? checkNum, bool? checkString}) {
if (value == null) {
return true;
} else if (value is String) {
var str = value.trim();
if (checkString == true) {
return str.isEmpty || str == 'null';
} else {
return str.isEmpty;
}
} else if (checkNum == true && value is num) {
return value == 0;
} else if (value is List) {
return value.isEmpty;
} else if (value is Map) {
return value.isEmpty;
} else if (value is Object) {
return value == {};
} else {
return false;
}
}