初始化

This commit is contained in:
谢宇宁
2026-09-15 15:44:13 +07:00
commit a23ba685e9
1065 changed files with 101122 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import '../hj_utils/date_time_util.dart';
/// 可空 int 扩展
extension IntNullableX on int? {
/// 人性化数量:1234 / 1.2w / 1.3亿;0、负数、null 一律 '0'
String get countStr {
final v = this ?? 0;
if (v <= 0) return '0';
if (v < 10000) return '$v';
if (v < 100000000) return '${(v / 10000).toStringAsFixed(1)}w';
return '${(v / 100000000).toStringAsFixed(1)}亿';
}
/// 同 [countStr],但 0/null 返回 [def](按钮上显示「点赞」而不是「0」)
String countOr(String? def) => (this ?? 0) <= 0 ? (def ?? '0') : countStr;
/// 秒数 → mm:ss 或 HH:mm:ss
String get hmsStr => DateTimeUtil.formatHMS(this ?? 0);
}