Files
syncrow-app/lib/features/devices/model/one_touch_model.dart
mohammad fed39b7198 setting
2024-09-30 17:02:31 +03:00

75 lines
2.1 KiB
Dart

// import 'package:syncrow_app/features/devices/model/status_model.dart';
// class OneTouchModel {
// bool firstSwitch;
// int firstCountDown;
// OneTouchModel({
// required this.firstSwitch,
// required this.firstCountDown,
// });
// factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
// late bool _switch;
// late int _count;
// for (int i = 0; i < jsonList.length; i++) {
// if (jsonList[i].code == 'switch_1') {
// _switch = jsonList[i].value ?? false;
// } else if (jsonList[i].code == 'countdown_1') {
// _count = jsonList[i].value ?? 0;
// }
// }
// return OneTouchModel(
// firstSwitch: _switch,
// firstCountDown: _count,
// );
// }
// }
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class OneTouchModel {
bool firstSwitch;
int firstCountDown;
status relay;
String light_mode;
String relay_status_1;
OneTouchModel(
{required this.firstSwitch,
required this.firstCountDown,
required this.light_mode,
required this.relay,
required this.relay_status_1});
factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
late bool _switch;
late int _count;
late String _relay;
late String _light_mode;
late String relay_status_1;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'switch_1') {
_switch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'countdown_1') {
_count = jsonList[i].value ?? 0;
} else if (jsonList[i].code == 'relay_status') {
_relay = jsonList[i].value ?? 0;
} else if (jsonList[i].code == 'light_mode') {
_light_mode = jsonList[i].value ?? 0;
} else if (jsonList[i].code == 'relay_status_1') {
relay_status_1 = jsonList[i].value ?? 0;
}
}
return OneTouchModel(
firstSwitch: _switch,
firstCountDown: _count,
light_mode: _light_mode,
relay: StatusExtension.fromString(_relay ) ,
relay_status_1: relay_status_1);
}
}