DartUtil class
Properties
-
hashCode
→ int
-
The hash code for this object.
no setterinherited
-
runtimeType
→ Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(Invocation invocation)
→ dynamic
-
Invoked when a nonexistent method or property is accessed.
inherited
-
toString()
→ String
-
A string representation of this object.
inherited
Static Methods
-
compareDate(dynamic date1, dynamic date2, [CompareType compareType = CompareType.equal])
→ bool
-
安全地比较两个日期,允许传入2个任意类型的数据,它们都会安全地转化为DateTime类型进行比较
-
compareNum(dynamic value1, dynamic value2, [CompareType compareType = CompareType.equal])
→ bool
-
安全地比较两个数字:小于、等于、大于、小于等于、大于等于。
-
compareString(dynamic value1, dynamic value2)
→ bool
-
安全地比较两个字符
-
debounce(Function fun, int wait, {Object? key})
→ void Function()
-
对函数进行防抖处理,如果在指定时间内多次执行函数,那么会忽略掉它,并重置等待时间,当等待时间结束后再执行函数
-
decodeString(String str)
→ String
-
将字符串编码压缩
-
diffDate(dynamic date1, dynamic date2)
→ int
-
获取date1和date2相差的时间,单位:毫秒
-
diffDay(dynamic date1, dynamic date2)
→ int
-
获取date1和date2相差的天数
-
dynamicToBaseType(dynamic value, [bool? strict])
→ dynamic
-
将动态类型转换成实际基础类型:String、int、double、num、bool,如果
-
dynamicToList<T>(dynamic value)
→ T
-
将动态类型转换成指定类型的 List 集合,转换前请判断数据类型是否是 List
-
dynamicToMap<T>(dynamic map)
→ dynamic
-
将动态类型转换成指定类型的 Map 集合,转换前请判断数据类型是否是 Map
-
dynamicToSet<T>(dynamic value)
→ T
-
将动态类型转换成指定类型的 Set 集合,转换前请判断数据类型是否是 Set
-
encodeString(String str)
→ String
-
将字符串编码压缩
-
formatDate(dynamic value, [String format = 'yyyy-MM-dd HH:mm:ss'])
→ String
-
以指定格式解析日期
-
formatSize(dynamic size)
→ String
-
格式化大小
-
formBase64(String str)
→ String
-
base64 转字符串
-
getCompareDate(DateTime date1, DateTime date2, [CompareType compareType = CompareType.equal])
→ DateTime
-
比较两个日期,如果为true,则返回date1,否则返回date2。
-
getFileSuffix(String fileName, {bool keepDot = false})
→ String?
-
获取文件名后缀
-
getUrlFileName(String? url)
→ String?
-
获取地址中的文件名
-
getUrlFileNameNoExtension(String? url)
→ String?
-
获取地址中的文件名但不包含扩展名
-
hasMatch(String? value, String pattern)
→ bool
-
-
isAudio(String fileName, [List<String>? ext])
→ bool
-
判断文件是否是音频
-
isBaseType(dynamic value)
→ bool
-
判断变量是否是基本数据类型
-
isBaseTypeString(String typeString)
→ bool
-
检查传入的类型字符串是否是基本类型字符串
-
isEmail(String s)
→ bool
-
判断是否是邮箱
-
isEmpty(dynamic value, {bool? checkNum, bool? checkString})
→ bool
-
判断一个变量是否为空,例如:null、''、[]、{}
-
isExcel(String fileName)
→ bool
-
判断文件是否是Excel
-
isHttp(String url)
→ bool
-
是否是 http 地址
-
isImage(String fileName, [List<String>? ext])
→ bool
-
判断文件是否是图片
-
isNotEmpty(dynamic value, {bool? checkNum, bool? checkString})
→ bool
-
判断一个变量是否不为空
-
isPhoneNumber(String s)
→ bool
-
判断是否是手机号
-
isPPT(String fileName)
→ bool
-
判断文件是否是PPT
-
isStaticImage(String fileName, [List<String>? ext])
→ bool
-
判断文件是否是静态图片
-
isVideo(String fileName, [List<String>? ext])
→ bool
-
判断文件是否是视频
-
isWord(String fileName)
→ bool
-
判断文件是否是Word
-
joinParentPath(String path, [String? parentPath])
→ String
-
拼接上级地址,返回新的path,主要过滤新地址尾部多余的/
-
listContains<E>(List<E> list, bool action(E element))
→ bool
-
判断list集合中是否包含满足某个条件的元素
-
listOnlyOne(List values, {bool allowAllNull = true})
→ bool
-
给定一个包含任意类型的变量数组,判断内部变量是否仅有一个元素不为null
-
loopGetListContent<T>(List<T> list, int index)
→ T
-
循环获取列表的内容,如果其索引大于列表的长度,则重头开始继续获取
-
millisecondToCountDown(int milliseconds)
→ String
-
时间戳转倒计时
-
runShareTask<T>(Object id, Future<T> task())
→ Future<T>
-
运行共享结果任务,当同时运行多个异步任务时,确保只处理一个任务、并排除其他任务,
当第一个任务运行结束时,其他任务会得到第一个任务的结果
-
safeBool(dynamic value, [bool defaultValue = false])
→ bool
-
安全解析bool类型
-
safeDate(dynamic value, [dynamic defaultValue])
→ DateTime
-
安全解析日期,支持字符串、时间戳等格式解析,如果格式不正确则返回defaultValue,
如果defaultValue为空,则会返回当前时间。
-
safeDouble(dynamic value, [double defaultValue = 0.0])
→ double
-
安全解析double,如果传递的value不是num类型,则返回默认值
-
safeInt(dynamic value, [int defaultValue = 0])
→ int
-
安全解析int,如果传递的value不是num类型,则返回默认值
-
safeList<T>(dynamic value, [List<T> defaultValue = const []])
→ List<T>
-
安全解析List,若解析失败则返回空List
-
safeString(dynamic value, [String defaultValue = ''])
→ String
-
安全解析String,如果传递的value为空,则返回一个默认值
-
throttle(Function fun, int wait, {Object? key, bool trailing = false})
→ void Function()
-
对目标函数进行包装,返回一个节流函数,会忽略指定时间内的多次执行
-
toBase64(String str)
→ String
-
字符串转 base64
-
toCrc32(String str)
→ String
-
使用 Crc32 哈希算法生成 8 位固定长度的字符串
-
toMd5(String str, {String salt = ''})
→ String
-
使用 md5 单向加密加密算法生成新的字符串