AI-Clipboard/lib/utils/obj_util.dart
fengshengxiong 50c2738fc5 搭建框架:
1.状态管理、路由、依赖注入
2.屏幕适配
3.日志封装
2024-05-07 18:16:51 +08:00

62 lines
1.5 KiB
Dart

/// [author] fengshengxiong
/// [date] 2024/5/7
/// [description] 对象工具类
library;
class ObjUtil {
static bool isNotEmptyString(String? str) {
return str == null || str.trim().isNotEmpty;
}
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;
}
/// get length.
static int getLength(Object? value) {
if (value == null) return 0;
if (value is String) {
return value.length;
} else if (value is Iterable) {
return value.length;
} else if (value is Map) {
return value.length;
} else {
return 0;
}
}
}