主要变更: 1. 全局修复类型转换问题,将多处`as int?`改为`(num?)?.toInt()`兼容浮点/字符串类型的数字字段 2. 移除废弃的nearby_p2p配对方式和对应的依赖包 3. 优化鸿蒙端快捷方式、引导页、路由导航的稳定性 4. 合并日志输出避免鸿蒙端IDE卡顿 5. 修复安卓端蓝牙权限冗余声明
84 lines
2.0 KiB
Dart
84 lines
2.0 KiB
Dart
// ============================================================
|
||
// 闲言APP — IP归属地查询结果模型
|
||
// 创建时间: 2026-05-11
|
||
// 更新时间: 2026-05-11
|
||
// 作用: 对应 /api/webapi/ip 接口响应数据
|
||
// 上次更新: 初始版本
|
||
// ============================================================
|
||
|
||
class IpLocationResult {
|
||
const IpLocationResult({
|
||
this.ip = '',
|
||
this.domain = '',
|
||
this.city = '',
|
||
this.fw,
|
||
this.num = 0,
|
||
this.queryTime,
|
||
});
|
||
|
||
final String ip;
|
||
final String domain;
|
||
final String city;
|
||
final String? fw;
|
||
final int num;
|
||
final DateTime? queryTime;
|
||
|
||
String get displayIp => domain.isNotEmpty ? domain : ip;
|
||
|
||
String get displayCity => city.isNotEmpty ? city : '未知';
|
||
|
||
String get displayRange => fw ?? '';
|
||
|
||
bool get hasLocation => city.isNotEmpty;
|
||
|
||
factory IpLocationResult.fromJson(Map<String, dynamic> json) {
|
||
return IpLocationResult(
|
||
ip: json['ip'] as String? ?? '',
|
||
domain: json['domain'] as String? ?? '',
|
||
city: json['city'] as String? ?? '',
|
||
fw: json['fw'] as String?,
|
||
num: _parseIntField(json['num']),
|
||
queryTime: DateTime.now(),
|
||
);
|
||
}
|
||
|
||
Map<String, dynamic> toJson() {
|
||
return {
|
||
'ip': ip,
|
||
'domain': domain,
|
||
'city': city,
|
||
'fw': fw,
|
||
'num': num,
|
||
};
|
||
}
|
||
|
||
IpLocationResult copyWith({
|
||
String? ip,
|
||
String? domain,
|
||
String? city,
|
||
String? fw,
|
||
int? num,
|
||
DateTime? queryTime,
|
||
}) {
|
||
return IpLocationResult(
|
||
ip: ip ?? this.ip,
|
||
domain: domain ?? this.domain,
|
||
city: city ?? this.city,
|
||
fw: fw ?? this.fw,
|
||
num: num ?? this.num,
|
||
queryTime: queryTime ?? this.queryTime,
|
||
);
|
||
}
|
||
|
||
/// 安全解析int字段,兼容后端返回int/double/String
|
||
static int _parseIntField(dynamic value) {
|
||
if (value is int) return value;
|
||
if (value is double) return value.toInt();
|
||
if (value is String) return int.tryParse(value) ?? 0;
|
||
return 0;
|
||
}
|
||
|
||
@override
|
||
String toString() => 'IpLocationResult(ip: $displayIp, city: $displayCity)';
|
||
}
|