初始化
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user