/// 钱包信息,来自 /mine/wallet class WalletModel { // ===== 收益 ===== int? income; //收益金币的整数部分 double? incomePot; //收益金币的零头,和 income 一起算总收益 num? vidIncome; //视频收益 // ===== 余额 ===== int? amount; //充值金币余额,购买后会被写回 int? integral; //积分 // ===== 剩余次数 ===== int? downloadCount; //视频下载次数 int? aiUndressFreeTimes; //AI 脱衣免费次数 int? todayAiFreeTimes; //今日 AI 免费次数 //字段顺序与上方声明一致,便于比对 WalletModel.fromJson(Map? json) { json ??= {}; income = json['income']; //后端可能下发 double / int / 数字字符串,统一按字符串解析。 //解析不了、或拿到 NaN/Infinity 都留 null 当没零头——balance 的 `~/` 吃到它们会抛 UnsupportedError final pot = double.tryParse('${json['incomePot'] ?? 0}'); incomePot = pot != null && pot.isFinite ? pot : null; vidIncome = json['vidIncome']; amount = json['amount']; integral = json['integral']; downloadCount = json['downloadCount']; aiUndressFreeTimes = json['aiUndressFreeTimes']; todayAiFreeTimes = json['todayAiFreeTimes']; } //收益总额:先放大 100 倍算再取整,避免 double 直接相加的精度误差 int get balance => ((income ?? 0) * 100.0 + (incomePot ?? 0) * 100) ~/ 100; }