Refactor device info model to handle optional fields more efficiently

This commit is contained in:
mohammad
2025-05-20 14:53:28 +03:00
parent b7a42af223
commit c2bf32af1c
2 changed files with 30 additions and 27 deletions

View File

@ -171,6 +171,7 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
deviceInfo = DeviceInfoModel.fromJson(response);
deviceName = deviceInfo.name;
emit(FlushSensorLoadingDeviceInfo(deviceInfo: deviceInfo));
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
} catch (e) {
emit(FlushSensorFailedState(error: e.toString()));
}

View File

@ -55,31 +55,33 @@ class DeviceInfoModel {
factory DeviceInfoModel.fromJson(Map<String, dynamic> json) {
return DeviceInfoModel(
activeTime: json['activeTime'],
category: json['category'],
categoryName: json['categoryName'],
createTime: json['createTime'],
gatewayId: json['gatewayId'],
icon: json['icon'],
activeTime: json['activeTime'] ?? '',
category: json['category'] ?? '',
categoryName: json['categoryName'] ?? '',
createTime: json['createTime'] ?? '',
gatewayId: json['gatewayId'] ?? '',
icon: json['icon'] ?? '',
ip: json['ip'] ?? "",
lat: json['lat'],
localKey: json['localKey'],
lon: json['lon'],
model: json['model'],
name: json['name'],
nodeId: json['nodeId'],
online: json['online'],
ownerId: json['ownerId'],
productName: json['productName'],
sub: json['sub'],
timeZone: json['timeZone'],
updateTime: json['updateTime'],
uuid: json['uuid'],
productUuid: json['productUuid'],
productType: json['productType'],
lat: json['lat'] ?? '',
localKey: json['localKey'] ?? '',
lon: json['lon'] ?? '',
model: json['model'] ?? '',
name: json['name'] ?? '',
nodeId: json['nodeId'] ?? '',
online: json['online'] ?? '',
ownerId: json['ownerId'] ?? '',
productName: json['productName'] ?? '',
sub: json['sub'] ?? '',
timeZone: json['timeZone'] ?? '',
updateTime: json['updateTime'] ?? '',
uuid: json['uuid'] ?? '',
productUuid: json['productUuid'] ?? '',
productType: json['productType'] ?? '',
permissionType: json['permissionType'] ?? '',
macAddress: json['macAddress'],
subspace: Subspace.fromJson(json['subspace']),
macAddress: json['macAddress'] ?? '',
subspace: json['subspace'] != null
? Subspace.fromJson(json['subspace'])
: throw ArgumentError('subspace cannot be null'),
);
}
@ -129,10 +131,10 @@ class Subspace {
factory Subspace.fromJson(Map<String, dynamic> json) {
return Subspace(
uuid: json['uuid'],
createdAt: json['createdAt'],
updatedAt: json['updatedAt'],
subspaceName: json['subspaceName'],
uuid: json['uuid'] ?? '',
createdAt: json['createdAt'] ?? '',
updatedAt: json['updatedAt'] ?? '',
subspaceName: json['subspaceName'] ?? '',
);
}