mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
Refactor device info model to handle optional fields more efficiently
This commit is contained in:
@ -171,6 +171,7 @@ class FlushSensorBloc extends Bloc<FlushSensorEvent, FlushSensorState> {
|
|||||||
deviceInfo = DeviceInfoModel.fromJson(response);
|
deviceInfo = DeviceInfoModel.fromJson(response);
|
||||||
deviceName = deviceInfo.name;
|
deviceName = deviceInfo.name;
|
||||||
emit(FlushSensorLoadingDeviceInfo(deviceInfo: deviceInfo));
|
emit(FlushSensorLoadingDeviceInfo(deviceInfo: deviceInfo));
|
||||||
|
emit(FlushSensorUpdateState(flushSensorModel: deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FlushSensorFailedState(error: e.toString()));
|
emit(FlushSensorFailedState(error: e.toString()));
|
||||||
}
|
}
|
||||||
|
@ -55,31 +55,33 @@ class DeviceInfoModel {
|
|||||||
|
|
||||||
factory DeviceInfoModel.fromJson(Map<String, dynamic> json) {
|
factory DeviceInfoModel.fromJson(Map<String, dynamic> json) {
|
||||||
return DeviceInfoModel(
|
return DeviceInfoModel(
|
||||||
activeTime: json['activeTime'],
|
activeTime: json['activeTime'] ?? '',
|
||||||
category: json['category'],
|
category: json['category'] ?? '',
|
||||||
categoryName: json['categoryName'],
|
categoryName: json['categoryName'] ?? '',
|
||||||
createTime: json['createTime'],
|
createTime: json['createTime'] ?? '',
|
||||||
gatewayId: json['gatewayId'],
|
gatewayId: json['gatewayId'] ?? '',
|
||||||
icon: json['icon'],
|
icon: json['icon'] ?? '',
|
||||||
ip: json['ip'] ?? "",
|
ip: json['ip'] ?? "",
|
||||||
lat: json['lat'],
|
lat: json['lat'] ?? '',
|
||||||
localKey: json['localKey'],
|
localKey: json['localKey'] ?? '',
|
||||||
lon: json['lon'],
|
lon: json['lon'] ?? '',
|
||||||
model: json['model'],
|
model: json['model'] ?? '',
|
||||||
name: json['name'],
|
name: json['name'] ?? '',
|
||||||
nodeId: json['nodeId'],
|
nodeId: json['nodeId'] ?? '',
|
||||||
online: json['online'],
|
online: json['online'] ?? '',
|
||||||
ownerId: json['ownerId'],
|
ownerId: json['ownerId'] ?? '',
|
||||||
productName: json['productName'],
|
productName: json['productName'] ?? '',
|
||||||
sub: json['sub'],
|
sub: json['sub'] ?? '',
|
||||||
timeZone: json['timeZone'],
|
timeZone: json['timeZone'] ?? '',
|
||||||
updateTime: json['updateTime'],
|
updateTime: json['updateTime'] ?? '',
|
||||||
uuid: json['uuid'],
|
uuid: json['uuid'] ?? '',
|
||||||
productUuid: json['productUuid'],
|
productUuid: json['productUuid'] ?? '',
|
||||||
productType: json['productType'],
|
productType: json['productType'] ?? '',
|
||||||
permissionType: json['permissionType'] ?? '',
|
permissionType: json['permissionType'] ?? '',
|
||||||
macAddress: json['macAddress'],
|
macAddress: json['macAddress'] ?? '',
|
||||||
subspace: Subspace.fromJson(json['subspace']),
|
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) {
|
factory Subspace.fromJson(Map<String, dynamic> json) {
|
||||||
return Subspace(
|
return Subspace(
|
||||||
uuid: json['uuid'],
|
uuid: json['uuid'] ?? '',
|
||||||
createdAt: json['createdAt'],
|
createdAt: json['createdAt'] ?? '',
|
||||||
updatedAt: json['updatedAt'],
|
updatedAt: json['updatedAt'] ?? '',
|
||||||
subspaceName: json['subspaceName'],
|
subspaceName: json['subspaceName'] ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user