Translate-Flutter/lib/util/obj_util.dart
fengshengxiong 70d663706c 第一版
2024-07-12 11:26:44 +08:00

51 lines
1.2 KiB
Dart

// Author: fengshengxiong
// Date: 2024/5/7
// Description: 对象工具类
class ObjUtil {
static bool isNotEmptyStr(String? str) {
return str != null && str.trim().isNotEmpty;
}
static String getStr(String? str) {
return isNotEmptyStr(str) ? str! : '';
}
static bool isNotEmptyList(Iterable? list) {
return list != null && list.isNotEmpty;
}
static bool isNotEmptyMap(Map? map) {
return map != null && map.isNotEmpty;
}
static bool isEmpty(Object? object) {
if (object == null) return true;
if (object is String && object.trim().isEmpty) {
return true;
} else if (object is Iterable && object.isEmpty) {
return true;
} else if (object is Map && object.isEmpty) {
return true;
}
return false;
}
static bool isNotEmpty(Object? object) {
return !isEmpty(object);
}
/// Returns true Two List Is Equal.
static bool twoListIsEqual(List? listA, List? listB) {
if (listA == listB) return true;
if (listA == null || listB == null) return false;
int length = listA.length;
if (length != listB.length) return false;
for (int i = 0; i < length; i++) {
if (!listA.contains(listB[i])) {
return false;
}
}
return true;
}
}