Files
monisuo/flutter_monisuo/lib/data/models/coin.dart
sion ffac6fc267 refactor: 将前端从 uni-app x 重构为 Flutter
变更内容:
- 删除 uni-app x 项目 (app/ 目录)
- 新增 Flutter 项目 (flutter_monisuo/ 目录)
- 新增部署脚本 (deploy/ 目录)

Flutter 项目功能:
- 用户登录/注册
- 首页资产概览
- 行情币种列表
- 交易买卖操作
- 资产账户管理
- 充值/提现/划转
- 深色主题
- JWT Token 认证

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-22 00:21:21 +08:00

107 lines
2.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// 币种模型
class Coin {
final int id;
final String code;
final String name;
final String? icon;
final double price;
final double? priceUsd;
final double? priceCny;
final int priceType; // 1=实时价格, 2=管理员设置
final double change24h;
final double? high24h;
final double? low24h;
final double? volume24h;
final int status;
final int sort;
Coin({
required this.id,
required this.code,
required this.name,
this.icon,
required this.price,
this.priceUsd,
this.priceCny,
required this.priceType,
required this.change24h,
this.high24h,
this.low24h,
this.volume24h,
required this.status,
this.sort = 0,
});
factory Coin.fromJson(Map<String, dynamic> json) {
return Coin(
id: json['id'] as int? ?? 0,
code: json['code'] as String? ?? '',
name: json['name'] as String? ?? '',
icon: json['icon'] as String?,
price: (json['price'] as num?)?.toDouble() ?? 0,
priceUsd: (json['priceUsd'] as num?)?.toDouble(),
priceCny: (json['priceCny'] as num?)?.toDouble(),
priceType: json['priceType'] as int? ?? 1,
change24h: (json['change24h'] as num?)?.toDouble() ?? 0,
high24h: (json['high24h'] as num?)?.toDouble(),
low24h: (json['low24h'] as num?)?.toDouble(),
volume24h: (json['volume24h'] as num?)?.toDouble(),
status: json['status'] as int? ?? 1,
sort: json['sort'] as int? ?? 0,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'code': code,
'name': name,
'icon': icon,
'price': price,
'priceUsd': priceUsd,
'priceCny': priceCny,
'priceType': priceType,
'change24h': change24h,
'high24h': high24h,
'low24h': low24h,
'volume24h': volume24h,
'status': status,
'sort': sort,
};
}
/// 显示图标Unicode 符号)
String get displayIcon {
const icons = {
'BTC': '\u20BF',
'ETH': '\u039E',
'SOL': '\u25CD',
'USDT': '\u20AE',
'DOGE': '\uD83D\uDC15',
'XRP': '\u2715',
'BNB': '\u25B3',
'ADA': '\u25C6',
};
return icons[code] ?? '\u25CF';
}
/// 格式化价格显示
String get formattedPrice {
if (price >= 1000) return price.toStringAsFixed(2);
if (price >= 1) return price.toStringAsFixed(4);
return price.toStringAsFixed(6);
}
/// 格式化涨跌幅
String get formattedChange {
final prefix = change24h >= 0 ? '+' : '';
return '$prefix${change24h.toStringAsFixed(2)}%';
}
/// 是否上涨
bool get isUp => change24h >= 0;
/// 是否为实时价格
bool get isRealtime => priceType == 1;
}