This commit is contained in:
mohammad
2024-11-14 10:23:00 +03:00
parent 6920d9129e
commit 48327fbbe5
9 changed files with 16 additions and 15 deletions
+6 -6
View File
@@ -1,27 +1,27 @@
import 'package:syncrow_app/features/devices/model/status_model.dart';
class SosModel {
String waterContactState;
String sosContactState;
int batteryPercentage;
SosModel({
required this.waterContactState,
required this.sosContactState,
required this.batteryPercentage,
});
factory SosModel.fromJson(List<StatusModel> jsonList) {
late String _waterContactState;
late String _sosContactState;
late int _batteryPercentage;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'sossensor_state') {
_waterContactState = jsonList[i].value ?? false;
if (jsonList[i].code == 'sos') {
_sosContactState = jsonList[i].value ?? '';
} else if (jsonList[i].code == 'battery_percentage') {
_batteryPercentage = jsonList[i].value ?? 0;
}
}
return SosModel(
waterContactState: _waterContactState,
sosContactState: _sosContactState,
batteryPercentage: _batteryPercentage,
);
}