Browse Source

获取固件版本api接口修改

weicu
fdp 1 year ago
parent
commit
67572565a2
  1. 8
      lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart
  2. 18
      lib/modules/ota_upgrade/model/ota_upgrade_model.dart

8
lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart

@ -193,7 +193,7 @@ class OtaUpgradeController extends GetxController {
}); });
// 处理API响应 // 处理API响应
if (response['info'] == null) { if (response['product'] == null) {
throw const FormatException('API 响应格式错误'); throw const FormatException('API 响应格式错误');
} }
@ -382,7 +382,8 @@ class OtaUpgradeController extends GetxController {
onReceiveProgress: (received, total) { onReceiveProgress: (received, total) {
if (total != -1) { if (total != -1) {
downloadProgress.value = received / total; downloadProgress.value = received / total;
detailedStatus.value = '正在下载固件包... ${(received / total * 100).toStringAsFixed(1)}%'; detailedStatus.value =
'正在下载固件包... ${(received / total * 100).toStringAsFixed(1)}%';
} }
}, },
); );
@ -491,7 +492,8 @@ class OtaUpgradeController extends GetxController {
progress.value = event.progress!; progress.value = event.progress!;
type.value = event.type!; type.value = event.type!;
isUpgrade.value = true; // 开始升级 isUpgrade.value = true; // 开始升级
detailedStatus.value = '升级进度: ${(event.progress! * 100).toStringAsFixed(1)}%'; detailedStatus.value =
'升级进度: ${(event.progress! * 100).toStringAsFixed(1)}%';
} }
if (event.event == 'onStartOTA') { if (event.event == 'onStartOTA') {
type.value = START_UPGRADING; type.value = START_UPGRADING;

18
lib/modules/ota_upgrade/model/ota_upgrade_model.dart

@ -12,8 +12,9 @@ class OtaConfigResp {
// 最终属性(不可变) // 最终属性(不可变)
final String? id; final String? id;
final String? factory; final int? factory;
final String? equipmentname; final int? devicetype;
final String? devicename;
final String? systemversion; final String? systemversion;
final String? updatepackageaddress; final String? updatepackageaddress;
final String? updatedescription; final String? updatedescription;
@ -21,7 +22,8 @@ class OtaConfigResp {
OtaConfigResp._({ OtaConfigResp._({
this.id, this.id,
this.factory, this.factory,
this.equipmentname, this.devicetype,
this.devicename,
this.systemversion, this.systemversion,
this.updatepackageaddress, this.updatepackageaddress,
this.updatedescription, this.updatedescription,
@ -30,13 +32,14 @@ class OtaConfigResp {
factory OtaConfigResp.fromJson(Map<String, dynamic> json) { factory OtaConfigResp.fromJson(Map<String, dynamic> json) {
print("数据获取fronTokenJson${json}"); print("数据获取fronTokenJson${json}");
// 修复1:安全获取嵌套的 user 字段 // 修复1:安全获取嵌套的 user 字段
final infoData = json['info'] as Map<String, dynamic>?; // 允许空值 final infoData = json['product'] as Map<String, dynamic>?; // 允许空值
// 更新单例实例 // 更新单例实例
return _instance = OtaConfigResp._( return _instance = OtaConfigResp._(
id: (infoData?['id'] as String?) ?? '', id: (infoData?['id'] as String?) ?? '',
factory: (infoData?['factory'] as String?) ?? '', factory: (infoData?['factoryid'] as int?) ?? 0,
equipmentname: (infoData?['equipmentname'] as String?) ?? '', devicetype: (infoData?['devicetype'] as int?) ?? 0,
devicename: (infoData?['devicename'] as String?) ?? '',
systemversion: (infoData?['systemversion'] as String?) ?? '', systemversion: (infoData?['systemversion'] as String?) ?? '',
updatepackageaddress: updatepackageaddress:
(infoData?['updatepackageaddress'] as String?) ?? '', (infoData?['updatepackageaddress'] as String?) ?? '',
@ -49,7 +52,8 @@ class OtaConfigResp {
'user': { 'user': {
'id': instance.id, 'id': instance.id,
'factory': instance.factory, 'factory': instance.factory,
'equipmentname': instance.equipmentname, 'devicetype': instance.devicetype,
'devicename': instance.devicename,
'systemversion': instance.systemversion, 'systemversion': instance.systemversion,
'updatepackageaddress': instance.updatepackageaddress, 'updatepackageaddress': instance.updatepackageaddress,
'updatedescription': instance.updatedescription, 'updatedescription': instance.updatedescription,

Loading…
Cancel
Save