mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-17 02:25:16 +00:00
setting
This commit is contained in:
@ -26,7 +26,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
bool oneGangGroup = false;
|
bool oneGangGroup = false;
|
||||||
List<DeviceModel> devicesList = [];
|
List<DeviceModel> devicesList = [];
|
||||||
|
|
||||||
OneGangBloc({required this.oneGangId, required this.switchCode}) : super(InitialState()) {
|
OneGangBloc({required this.oneGangId, required this.switchCode})
|
||||||
|
: super(InitialState()) {
|
||||||
on<InitialEvent>(_fetchOneGangStatus);
|
on<InitialEvent>(_fetchOneGangStatus);
|
||||||
on<OneGangUpdated>(_oneGangUpdated);
|
on<OneGangUpdated>(_oneGangUpdated);
|
||||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||||
@ -49,7 +50,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
on<GroupAllOffEvent>(_groupAllOff);
|
on<GroupAllOffEvent>(_groupAllOff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchOneGangStatus(InitialEvent event, Emitter<OneGangState> emit) async {
|
void _fetchOneGangStatus(
|
||||||
|
InitialEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
||||||
@ -68,18 +70,21 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
|
|
||||||
_listenToChanges() {
|
_listenToChanges() {
|
||||||
try {
|
try {
|
||||||
DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$oneGangId');
|
DatabaseReference ref =
|
||||||
|
FirebaseDatabase.instance.ref('device-status/$oneGangId');
|
||||||
Stream<DatabaseEvent> stream = ref.onValue;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
|
|
||||||
stream.listen((DatabaseEvent event) async {
|
stream.listen((DatabaseEvent event) async {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
}
|
}
|
||||||
Map<dynamic, dynamic> usersMap = event.snapshot.value as Map<dynamic, dynamic>;
|
Map<dynamic, dynamic> usersMap =
|
||||||
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
List<StatusModel> statusList = [];
|
List<StatusModel> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(StatusModel(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(StatusModel(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = OneGangModel.fromJson(statusList);
|
deviceStatus = OneGangModel.fromJson(statusList);
|
||||||
@ -94,7 +99,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
emit(UpdateState(oneGangModel: deviceStatus));
|
emit(UpdateState(oneGangModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<OneGangState> emit) async {
|
void _changeFirstSwitch(
|
||||||
|
ChangeFirstSwitchStatusEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
deviceStatus.firstSwitch = !event.value;
|
deviceStatus.firstSwitch = !event.value;
|
||||||
@ -119,17 +125,20 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeSliding(ChangeSlidingSegment event, Emitter<OneGangState> emit) async {
|
void _changeSliding(
|
||||||
|
ChangeSlidingSegment event, Emitter<OneGangState> emit) async {
|
||||||
emit(ChangeSlidingSegmentState(value: event.value));
|
emit(ChangeSlidingSegmentState(value: event.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setCounterValue(SetCounterValue event, Emitter<OneGangState> emit) async {
|
void _setCounterValue(
|
||||||
|
SetCounterValue event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
||||||
int seconds = 0;
|
int seconds = 0;
|
||||||
try {
|
try {
|
||||||
seconds = event.duration.inSeconds;
|
seconds = event.duration.inSeconds;
|
||||||
final response = await DevicesAPI.controlDevice(
|
final response = await DevicesAPI.controlDevice(
|
||||||
DeviceControlModel(deviceId: oneGangId, code: event.deviceCode, value: seconds),
|
DeviceControlModel(
|
||||||
|
deviceId: oneGangId, code: event.deviceCode, value: seconds),
|
||||||
oneGangId);
|
oneGangId);
|
||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
@ -152,7 +161,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getCounterValue(GetCounterEvent event, Emitter<OneGangState> emit) async {
|
void _getCounterValue(
|
||||||
|
GetCounterEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
var response = await DevicesAPI.getDeviceStatus(oneGangId);
|
||||||
@ -241,7 +251,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
deviceId: oneGangId,
|
deviceId: oneGangId,
|
||||||
);
|
);
|
||||||
List<dynamic> jsonData = response;
|
List<dynamic> jsonData = response;
|
||||||
listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
listSchedule =
|
||||||
|
jsonData.map((item) => ScheduleModel.fromJson(item)).toList();
|
||||||
emit(InitialState());
|
emit(InitialState());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final errorData = e.response!.data;
|
final errorData = e.response!.data;
|
||||||
@ -252,12 +263,13 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
if (dateTime == null) return null;
|
if (dateTime == null) return null;
|
||||||
DateTime dateTimeWithoutSeconds =
|
DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month,
|
||||||
DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute);
|
dateTime.day, dateTime.hour, dateTime.minute);
|
||||||
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future toggleChange(ToggleScheduleEvent event, Emitter<OneGangState> emit) async {
|
Future toggleChange(
|
||||||
|
ToggleScheduleEvent event, Emitter<OneGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.changeSchedule(
|
final response = await DevicesAPI.changeSchedule(
|
||||||
@ -276,7 +288,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future deleteSchedule(DeleteScheduleEvent event, Emitter<OneGangState> emit) async {
|
Future deleteSchedule(
|
||||||
|
DeleteScheduleEvent event, Emitter<OneGangState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
final response = await DevicesAPI.deleteSchedule(
|
final response = await DevicesAPI.deleteSchedule(
|
||||||
@ -296,8 +309,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toggleCreateSchedule(
|
||||||
void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter<OneGangState> emit) {
|
ToggleCreateScheduleEvent event, Emitter<OneGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
createSchedule = !createSchedule;
|
createSchedule = !createSchedule;
|
||||||
selectedDays.clear();
|
selectedDays.clear();
|
||||||
@ -326,7 +339,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
|
|
||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
void toggleSelectedIndex(ToggleSelectedEvent event, Emitter<OneGangState> emit) {
|
void toggleSelectedIndex(
|
||||||
|
ToggleSelectedEvent event, Emitter<OneGangState> emit) {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
selectedTabIndex = event.index;
|
selectedTabIndex = event.index;
|
||||||
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
emit(ChangeSlidingSegmentState(value: selectedTabIndex));
|
||||||
@ -335,7 +349,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
List<GroupOneGangModel> groupOneGangList = [];
|
List<GroupOneGangModel> groupOneGangList = [];
|
||||||
bool allSwitchesOn = true;
|
bool allSwitchesOn = true;
|
||||||
|
|
||||||
void _fetchOneGangWizardStatus(InitialWizardEvent event, Emitter<OneGangState> emit) async {
|
void _fetchOneGangWizardStatus(
|
||||||
|
InitialWizardEvent event, Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingInitialState());
|
emit(LoadingInitialState());
|
||||||
try {
|
try {
|
||||||
devicesList = [];
|
devicesList = [];
|
||||||
@ -345,7 +360,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '1G');
|
HomeCubit.getInstance().selectedSpace?.id ?? '', '1G');
|
||||||
|
|
||||||
for (int i = 0; i < devicesList.length; i++) {
|
for (int i = 0; i < devicesList.length; i++) {
|
||||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
var response =
|
||||||
|
await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||||
List<StatusModel> statusModelList = [];
|
List<StatusModel> statusModelList = [];
|
||||||
for (var status in response['status']) {
|
for (var status in response['status']) {
|
||||||
statusModelList.add(StatusModel.fromJson(status));
|
statusModelList.add(StatusModel.fromJson(status));
|
||||||
@ -366,15 +382,16 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: allSwitchesOn));
|
emit(UpdateGroupState(
|
||||||
|
oneGangList: groupOneGangList, allSwitches: allSwitchesOn));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(FailedState(error: e.toString()));
|
emit(FailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeFirstWizardSwitch(
|
void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event,
|
||||||
ChangeFirstWizardSwitchStatusEvent event, Emitter<OneGangState> emit) async {
|
Emitter<OneGangState> emit) async {
|
||||||
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
emit(LoadingNewSate(oneGangModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
bool allSwitchesValue = true;
|
bool allSwitchesValue = true;
|
||||||
@ -387,7 +404,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: allSwitchesValue));
|
emit(UpdateGroupState(
|
||||||
|
oneGangList: groupOneGangList, allSwitches: allSwitchesValue));
|
||||||
|
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
code: 'switch_1',
|
code: 'switch_1',
|
||||||
@ -415,7 +433,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: true));
|
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: true));
|
||||||
|
|
||||||
// Get a list of all device IDs
|
// Get a list of all device IDs
|
||||||
List<String> allDeviceIds = groupOneGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupOneGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
// First call for switch_1
|
// First call for switch_1
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
@ -447,7 +466,8 @@ class OneGangBloc extends Bloc<OneGangEvent, OneGangState> {
|
|||||||
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: false));
|
emit(UpdateGroupState(oneGangList: groupOneGangList, allSwitches: false));
|
||||||
|
|
||||||
// Get a list of all device IDs
|
// Get a list of all device IDs
|
||||||
List<String> allDeviceIds = groupOneGangList.map((device) => device.deviceId).toList();
|
List<String> allDeviceIds =
|
||||||
|
groupOneGangList.map((device) => device.deviceId).toList();
|
||||||
|
|
||||||
// First call for switch_1
|
// First call for switch_1
|
||||||
final response = await DevicesAPI.deviceBatchController(
|
final response = await DevicesAPI.deviceBatchController(
|
||||||
|
@ -13,14 +13,17 @@ import 'package:syncrow_app/features/devices/model/schedule_model.dart';
|
|||||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
||||||
final String oneTouchId;
|
final String oneTouchId;
|
||||||
final String switchCode;
|
final String switchCode;
|
||||||
OneTouchModel deviceStatus = OneTouchModel(
|
OneTouchModel deviceStatus = OneTouchModel(
|
||||||
firstSwitch: false,
|
firstSwitch: false,
|
||||||
firstCountDown: 0,
|
firstCountDown: 0,
|
||||||
);
|
light_mode: '',
|
||||||
|
relay: status.off,
|
||||||
|
relay_status_1: '');
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
|
||||||
bool oneTouchGroup = false;
|
bool oneTouchGroup = false;
|
||||||
@ -47,6 +50,7 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
on<ChangeFirstWizardSwitchStatusEvent>(_changeFirstWizardSwitch);
|
||||||
on<GroupAllOnEvent>(_groupAllOn);
|
on<GroupAllOnEvent>(_groupAllOn);
|
||||||
on<GroupAllOffEvent>(_groupAllOff);
|
on<GroupAllOffEvent>(_groupAllOff);
|
||||||
|
on<ChangeStatusEvent>(_changeStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchOneTouchStatus(
|
void _fetchOneTouchStatus(
|
||||||
@ -500,4 +504,124 @@ class OneTouchBloc extends Bloc<OneTouchEvent, OneTouchState> {
|
|||||||
add(const InitialEvent(groupScreen: true));
|
add(const InitialEvent(groupScreen: true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String statusSelected = '';
|
||||||
|
String optionSelected = '';
|
||||||
|
// void _changeStatus(
|
||||||
|
// ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||||
|
// emit(LoadingNewSate(oneTouchModel: deviceStatus));
|
||||||
|
// try {
|
||||||
|
// // deviceStatus.firstSwitch = !event.value;
|
||||||
|
// emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
|
// print('statusSelected====${statusSelected}');
|
||||||
|
// if (optionSelected == "relay_status") {
|
||||||
|
// if (statusSelected == 'Power On') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId,
|
||||||
|
// code: 'relay_status',
|
||||||
|
// value: 'power_on'),
|
||||||
|
// oneTouchId);
|
||||||
|
// } else if (statusSelected == 'Power Off') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId,
|
||||||
|
// code: 'relay_status',
|
||||||
|
// value: 'power_off'),
|
||||||
|
// oneTouchId);
|
||||||
|
// } else if (statusSelected == 'Restart Memory') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId, code: 'relay_status', value: 'last'),
|
||||||
|
// oneTouchId);
|
||||||
|
// }
|
||||||
|
// } else if (optionSelected == "light_mode") {
|
||||||
|
// if (statusSelected == 'Off') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId, code: 'light_mode', value: 'none'),
|
||||||
|
// oneTouchId);
|
||||||
|
// } else if (statusSelected == 'On/Off Status') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId, code: 'light_mode', value: 'relay'),
|
||||||
|
// oneTouchId);
|
||||||
|
// } else if (statusSelected == 'Switch Position') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId, code: 'relay_status', value: 'pos'),
|
||||||
|
// oneTouchId);
|
||||||
|
// }
|
||||||
|
// } else if (optionSelected == "relay_status_1") {
|
||||||
|
// if (statusSelected == 'Power On') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId,
|
||||||
|
// code: 'relay_status_1',
|
||||||
|
// value: 'power_off'),
|
||||||
|
// oneTouchId);
|
||||||
|
// } else if (statusSelected == 'Power Off') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId,
|
||||||
|
// code: 'relay_status_1',
|
||||||
|
// value: 'power_on'),
|
||||||
|
// oneTouchId);
|
||||||
|
// } else if (statusSelected == 'Restart Memory') {
|
||||||
|
// final response = await DevicesAPI.controlDevice(
|
||||||
|
// DeviceControlModel(
|
||||||
|
// deviceId: oneTouchId, code: 'relay_status_1', value: 'last'),
|
||||||
|
// oneTouchId);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||||
|
// } catch (_) {
|
||||||
|
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
void _changeStatus(
|
||||||
|
ChangeStatusEvent event, Emitter<OneTouchState> emit) async {
|
||||||
|
// emit(LoadingNewState(oneTouchModel: deviceStatus));
|
||||||
|
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
|
try {
|
||||||
|
emit(UpdateState(oneTouchModel: deviceStatus));
|
||||||
|
await _handleDeviceControl(event.deviceId);
|
||||||
|
add(InitialEvent(groupScreen: oneTouchGroup));
|
||||||
|
} catch (error) {
|
||||||
|
print('Error controlling device: $error');
|
||||||
|
add(InitialEvent(groupScreen: oneTouchGroup));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _handleDeviceControl(String deviceId) async {
|
||||||
|
final Map<String, Map<String, String>> controlMap = {
|
||||||
|
"relay_status": {
|
||||||
|
'Power On': 'power_on',
|
||||||
|
'Power Off': 'power_off',
|
||||||
|
'Restart Memory': 'last',
|
||||||
|
},
|
||||||
|
"light_mode": {
|
||||||
|
'Off': 'none',
|
||||||
|
'On/Off Status': 'relay',
|
||||||
|
'Switch Position': 'pos',
|
||||||
|
},
|
||||||
|
"relay_status_1": {
|
||||||
|
'Power On': 'power_off',
|
||||||
|
'Power Off': 'power_on',
|
||||||
|
'Restart Memory': 'last',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
final selectedControl = controlMap[optionSelected]?[statusSelected];
|
||||||
|
if (selectedControl != null) {
|
||||||
|
await DevicesAPI.controlDevice(
|
||||||
|
DeviceControlModel(
|
||||||
|
deviceId: oneTouchId, code: optionSelected, value: selectedControl),
|
||||||
|
oneTouchId,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
print('Invalid statusSelected or optionSelected');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,3 +139,8 @@ class ChangeFirstWizardSwitchStatusEvent extends OneTouchEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [value, deviceId];
|
List<Object> get props => [value, deviceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ChangeStatusEvent extends OneTouchEvent {
|
||||||
|
final String deviceId;
|
||||||
|
const ChangeStatusEvent({this.deviceId = ''});
|
||||||
|
}
|
||||||
|
@ -1,28 +1,74 @@
|
|||||||
|
// 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/features/devices/model/status_model.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
class OneTouchModel {
|
class OneTouchModel {
|
||||||
bool firstSwitch;
|
bool firstSwitch;
|
||||||
int firstCountDown;
|
int firstCountDown;
|
||||||
|
status relay;
|
||||||
|
String light_mode;
|
||||||
|
String relay_status_1;
|
||||||
|
|
||||||
OneTouchModel({
|
OneTouchModel(
|
||||||
required this.firstSwitch,
|
{required this.firstSwitch,
|
||||||
required this.firstCountDown,
|
required this.firstCountDown,
|
||||||
});
|
required this.light_mode,
|
||||||
|
required this.relay,
|
||||||
|
required this.relay_status_1});
|
||||||
|
|
||||||
factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
|
factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
|
||||||
late bool _switch;
|
late bool _switch;
|
||||||
late int _count;
|
late int _count;
|
||||||
|
late String _relay;
|
||||||
|
late String _light_mode;
|
||||||
|
late String relay_status_1;
|
||||||
|
|
||||||
for (int i = 0; i < jsonList.length; i++) {
|
for (int i = 0; i < jsonList.length; i++) {
|
||||||
if (jsonList[i].code == 'switch_1') {
|
if (jsonList[i].code == 'switch_1') {
|
||||||
_switch = jsonList[i].value ?? false;
|
_switch = jsonList[i].value ?? false;
|
||||||
} else if (jsonList[i].code == 'countdown_1') {
|
} else if (jsonList[i].code == 'countdown_1') {
|
||||||
_count = jsonList[i].value ?? 0;
|
_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(
|
return OneTouchModel(
|
||||||
firstSwitch: _switch,
|
firstSwitch: _switch,
|
||||||
firstCountDown: _count,
|
firstCountDown: _count,
|
||||||
);
|
light_mode: _light_mode,
|
||||||
|
relay: StatusExtension.fromString(_relay ) ,
|
||||||
|
relay_status_1: relay_status_1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,17 +31,7 @@ class CircularButton extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
// () {
|
|
||||||
// Navigator.push(
|
|
||||||
// context,
|
|
||||||
// PageRouteBuilder(
|
|
||||||
// pageBuilder: (context, animation1, animation2) =>
|
|
||||||
// TimerScheduleScreen(
|
|
||||||
// switchCode: 'switch_1',
|
|
||||||
// device: device!,
|
|
||||||
// deviceCode: 'countdown_1',
|
|
||||||
// )));
|
|
||||||
// },
|
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
@ -76,9 +76,11 @@ class OneTouchScreen extends StatelessWidget {
|
|||||||
child: BlocBuilder<OneTouchBloc, OneTouchState>(
|
child: BlocBuilder<OneTouchBloc, OneTouchState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
OneTouchModel oneTouchModel = OneTouchModel(
|
OneTouchModel oneTouchModel = OneTouchModel(
|
||||||
firstSwitch: false,
|
firstSwitch: false,
|
||||||
firstCountDown: 0,
|
firstCountDown: 0,
|
||||||
);
|
light_mode: '',
|
||||||
|
relay: status.off,
|
||||||
|
relay_status_1: '');
|
||||||
|
|
||||||
List<GroupOneTouchModel> groupOneTouchModel = [];
|
List<GroupOneTouchModel> groupOneTouchModel = [];
|
||||||
bool allSwitchesOn = false;
|
bool allSwitchesOn = false;
|
||||||
@ -193,7 +195,9 @@ class OneTouchScreen extends StatelessWidget {
|
|||||||
pageBuilder: (context,
|
pageBuilder: (context,
|
||||||
animation1,
|
animation1,
|
||||||
animation2) =>
|
animation2) =>
|
||||||
OneTouchSetting()));
|
OneTouchSetting(
|
||||||
|
device: device,
|
||||||
|
)));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart';
|
import 'package:syncrow_app/features/devices/bloc/one_touch_bloc/one_touch_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_event.dart';
|
import 'package:syncrow_app/features/devices/bloc/one_touch_bloc/one_touch_event.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/one_gang_bloc/one_gang_state.dart';
|
import 'package:syncrow_app/features/devices/bloc/one_touch_bloc/one_touch_state.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/group_one_gang_model.dart';
|
import 'package:syncrow_app/features/devices/model/group_one_touch_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/one_gang/one_gang_list.dart';
|
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
class OneTouchSetting extends StatelessWidget {
|
class OneTouchSetting extends StatelessWidget {
|
||||||
const OneTouchSetting({super.key, this.device});
|
const OneTouchSetting({super.key, this.device});
|
||||||
@ -16,31 +19,470 @@ class OneTouchSetting extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
List<GroupOneGangModel> groupOneGangModel = [];
|
List<GroupOneTouchModel> groupOneTouchModel = [];
|
||||||
|
|
||||||
return DefaultScaffold(
|
return DefaultScaffold(
|
||||||
|
title: 'Setting',
|
||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (context) =>
|
create: (context) =>
|
||||||
OneGangBloc(switchCode: '', oneGangId: device?.uuid ?? '')
|
OneTouchBloc(switchCode: '', oneTouchId: device?.uuid ?? '')
|
||||||
..add(InitialWizardEvent()),
|
..add(InitialWizardEvent()),
|
||||||
child: BlocBuilder<OneGangBloc, OneGangState>(
|
child: BlocBuilder<OneTouchBloc, OneTouchState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
bool allSwitchesOn = false;
|
final oneTouchBloc = BlocProvider.of<OneTouchBloc>(context);
|
||||||
|
|
||||||
if (state is UpdateGroupState) {
|
bool allSwitchesOn = false;
|
||||||
groupOneGangModel = state.oneGangList;
|
|
||||||
allSwitchesOn = state.allSwitches;
|
if (state is UpdateGroupState) {
|
||||||
}
|
groupOneTouchModel = state.oneTouchList;
|
||||||
return state is LoadingInitialState
|
allSwitchesOn = state.allSwitches;
|
||||||
? const Center(
|
}
|
||||||
child: DefaultContainer(
|
return state is LoadingInitialState
|
||||||
width: 50,
|
? const Center(
|
||||||
height: 50,
|
child: DefaultContainer(
|
||||||
child: CircularProgressIndicator()),
|
width: 50,
|
||||||
)
|
height: 50,
|
||||||
: Container();
|
child: CircularProgressIndicator()),
|
||||||
},
|
)
|
||||||
),
|
: Column(
|
||||||
));
|
children: [
|
||||||
|
Container(
|
||||||
|
child: DefaultContainer(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
oneTouchBloc.optionSelected =
|
||||||
|
'relay_status';
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return RestartStatusDialog(
|
||||||
|
cancelTab: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
confirmTab: () {
|
||||||
|
oneTouchBloc.add(ChangeStatusEvent(
|
||||||
|
deviceId: device!.uuid!));
|
||||||
|
},
|
||||||
|
title: 'Restart Status',
|
||||||
|
label1: 'Power Off',
|
||||||
|
label2: 'Power On',
|
||||||
|
label3: 'Restart Memory',
|
||||||
|
onTapLabel1: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
},
|
||||||
|
onTapLabel2: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
},
|
||||||
|
onTapLabel3: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
bottom: 10, top: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const BodyLarge(
|
||||||
|
fontSize: 15,
|
||||||
|
text: 'Restart Status',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
BodyMedium(
|
||||||
|
fontSize: 13,
|
||||||
|
text: oneTouchBloc
|
||||||
|
.deviceStatus.relay.value,
|
||||||
|
fontColor:
|
||||||
|
ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
const Icon(
|
||||||
|
Icons.keyboard_arrow_right,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
color: ColorsManager.graysColor,
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
bottom: 10, top: 10),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () {
|
||||||
|
oneTouchBloc.optionSelected =
|
||||||
|
'light_mode';
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return RestartStatusDialog(
|
||||||
|
cancelTab: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
confirmTab: () {
|
||||||
|
oneTouchBloc.add(
|
||||||
|
const ChangeStatusEvent());
|
||||||
|
},
|
||||||
|
title: 'Indicator Status',
|
||||||
|
label1: 'Off',
|
||||||
|
label2: 'On/Off Status',
|
||||||
|
label3: 'Switch Position',
|
||||||
|
onTapLabel1: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
},
|
||||||
|
onTapLabel2: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
},
|
||||||
|
onTapLabel3: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: SizedBox(
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const BodyLarge(
|
||||||
|
fontSize: 15,
|
||||||
|
text: 'Indicator Status',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
BodyMedium(
|
||||||
|
fontSize: 13,
|
||||||
|
text: oneTouchBloc
|
||||||
|
.deviceStatus.light_mode,
|
||||||
|
fontColor: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
const Icon(
|
||||||
|
Icons.keyboard_arrow_right,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
color: ColorsManager.graysColor,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
bottom: 10, top: 10),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: () {
|
||||||
|
oneTouchBloc.optionSelected =
|
||||||
|
'relay_status_1';
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return RestartStatusDialog(
|
||||||
|
cancelTab: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
confirmTab: () {},
|
||||||
|
title: 'Restart Status 1',
|
||||||
|
label1: 'Power Off',
|
||||||
|
label2: 'Power On',
|
||||||
|
label3: 'Restart Memory',
|
||||||
|
onTapLabel1: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
print(
|
||||||
|
'Selected: $selected for Label 1');
|
||||||
|
},
|
||||||
|
onTapLabel2: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
print(
|
||||||
|
'Selected: $selected for Label 2');
|
||||||
|
},
|
||||||
|
onTapLabel3: (selected) {
|
||||||
|
oneTouchBloc.statusSelected =
|
||||||
|
selected;
|
||||||
|
print(
|
||||||
|
'Selected: $selected for Label 3');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const BodyLarge(
|
||||||
|
fontSize: 15,
|
||||||
|
text: 'Restart Status 1',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
BodyMedium(
|
||||||
|
fontSize: 13,
|
||||||
|
text: oneTouchBloc.deviceStatus
|
||||||
|
.relay_status_1,
|
||||||
|
fontColor:
|
||||||
|
ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
const Icon(
|
||||||
|
Icons.keyboard_arrow_right,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RestartStatusDialog extends StatefulWidget {
|
||||||
|
final String label1;
|
||||||
|
final String label2;
|
||||||
|
final String label3;
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
// Add onTap callbacks as parameters
|
||||||
|
final Function(String)? onTapLabel1;
|
||||||
|
final Function(String)? onTapLabel2;
|
||||||
|
final Function(String)? onTapLabel3;
|
||||||
|
final Function()? cancelTab;
|
||||||
|
final Function()? confirmTab;
|
||||||
|
|
||||||
|
RestartStatusDialog({
|
||||||
|
required this.label1,
|
||||||
|
required this.label2,
|
||||||
|
required this.label3,
|
||||||
|
required this.title,
|
||||||
|
this.onTapLabel1,
|
||||||
|
this.onTapLabel2,
|
||||||
|
this.onTapLabel3,
|
||||||
|
required this.cancelTab,
|
||||||
|
required this.confirmTab,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_RestartStatusDialogState createState() => _RestartStatusDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RestartStatusDialogState extends State<RestartStatusDialog> {
|
||||||
|
String _selectedOption = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
BodyLarge(
|
||||||
|
text: widget.title,
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
fontColor: ColorsManager.primaryColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.only(left: 15, right: 15),
|
||||||
|
child: Divider(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 15, right: 15),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
_buildCheckboxOption(
|
||||||
|
label: widget.label1,
|
||||||
|
onTap: widget.onTapLabel1,
|
||||||
|
),
|
||||||
|
_buildCheckboxOption(
|
||||||
|
label: widget.label2,
|
||||||
|
onTap: widget.onTapLabel2,
|
||||||
|
),
|
||||||
|
_buildCheckboxOption(
|
||||||
|
label: widget.label3,
|
||||||
|
onTap: widget.onTapLabel3,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
right: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
top: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
child: SizedBox(
|
||||||
|
child: InkWell(
|
||||||
|
onTap: widget.cancelTab,
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(15),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'Cancel',
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w400),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
left: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
top: BorderSide(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
child: InkWell(
|
||||||
|
onTap: widget.confirmTab,
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(15),
|
||||||
|
child: Center(
|
||||||
|
child: Text(
|
||||||
|
'Confirm',
|
||||||
|
style: TextStyle(
|
||||||
|
color: ColorsManager.primaryColor,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w400),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCheckboxOption(
|
||||||
|
{required String label, Function(String)? onTap}) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 10, top: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
BodyMedium(
|
||||||
|
text: label,
|
||||||
|
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w400),
|
||||||
|
),
|
||||||
|
CircularCheckbox(
|
||||||
|
value: _selectedOption ==
|
||||||
|
label, // True if the current option is selected
|
||||||
|
onChanged: (bool? value) {
|
||||||
|
if (value == true) {
|
||||||
|
setState(() {
|
||||||
|
_selectedOption = label; // Select only one option
|
||||||
|
});
|
||||||
|
if (onTap != null) {
|
||||||
|
onTap(label); // Call the passed onTap callback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CircularCheckbox extends StatefulWidget {
|
||||||
|
final bool value;
|
||||||
|
final ValueChanged<bool?> onChanged;
|
||||||
|
|
||||||
|
CircularCheckbox({required this.value, required this.onChanged});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_CircularCheckboxState createState() => _CircularCheckboxState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CircularCheckboxState extends State<CircularCheckbox> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
widget.onChanged(!widget.value);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: widget.value
|
||||||
|
? ColorsManager.primaryColorWithOpacity.withOpacity(0.01)
|
||||||
|
: Colors.grey,
|
||||||
|
width: 2.0,
|
||||||
|
),
|
||||||
|
color: widget.value
|
||||||
|
? ColorsManager.primaryColorWithOpacity
|
||||||
|
: Colors.transparent,
|
||||||
|
),
|
||||||
|
width: 24.0,
|
||||||
|
height: 24.0,
|
||||||
|
child: widget.value
|
||||||
|
? const Icon(
|
||||||
|
Icons.check,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 16.0,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class DevicesAPI {
|
|||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId),
|
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId),
|
||||||
body: controlModel.toJson(),
|
body: controlModel.toJson(),
|
||||||
showServerMessage: false,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
@ -72,7 +72,8 @@ class DevicesAPI {
|
|||||||
|
|
||||||
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
|
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.deviceFunctionsStatus.replaceAll('{deviceUuid}', deviceId),
|
path: ApiEndpoints.deviceFunctionsStatus
|
||||||
|
.replaceAll('{deviceUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
@ -82,7 +83,9 @@ class DevicesAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<Map<String, dynamic>> renamePass(
|
static Future<Map<String, dynamic>> renamePass(
|
||||||
{required String name, required String doorLockUuid, required String passwordId}) async {
|
{required String name,
|
||||||
|
required String doorLockUuid,
|
||||||
|
required String passwordId}) async {
|
||||||
final response = await _httpService.put(
|
final response = await _httpService.put(
|
||||||
path: ApiEndpoints.renamePassword
|
path: ApiEndpoints.renamePassword
|
||||||
.replaceAll('{doorLockUuid}', doorLockUuid)
|
.replaceAll('{doorLockUuid}', doorLockUuid)
|
||||||
@ -107,7 +110,8 @@ class DevicesAPI {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<DeviceModel>> getDeviceByGroupName(String unitId, String groupName) async {
|
static Future<List<DeviceModel>> getDeviceByGroupName(
|
||||||
|
String unitId, String groupName) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.devicesByGroupName
|
path: ApiEndpoints.devicesByGroupName
|
||||||
.replaceAll('{unitUuid}', unitId)
|
.replaceAll('{unitUuid}', unitId)
|
||||||
@ -146,7 +150,8 @@ class DevicesAPI {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<DeviceModel>> getDevicesByGatewayId(String gatewayId) async {
|
static Future<List<DeviceModel>> getDevicesByGatewayId(
|
||||||
|
String gatewayId) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
|
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
@ -168,7 +173,8 @@ class DevicesAPI {
|
|||||||
String deviceId,
|
String deviceId,
|
||||||
) async {
|
) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
|
path: ApiEndpoints.getTemporaryPassword
|
||||||
|
.replaceAll('{doorLockUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
@ -179,7 +185,8 @@ class DevicesAPI {
|
|||||||
|
|
||||||
static Future getOneTimePasswords(String deviceId) async {
|
static Future getOneTimePasswords(String deviceId) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getOneTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
|
path: ApiEndpoints.getOneTimeTemporaryPassword
|
||||||
|
.replaceAll('{doorLockUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
@ -190,7 +197,8 @@ class DevicesAPI {
|
|||||||
|
|
||||||
static Future getTimeLimitPasswords(String deviceId) async {
|
static Future getTimeLimitPasswords(String deviceId) async {
|
||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getMultipleTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
|
path: ApiEndpoints.getMultipleTimeTemporaryPassword
|
||||||
|
.replaceAll('{doorLockUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
@ -215,10 +223,12 @@ class DevicesAPI {
|
|||||||
"invalidTime": invalidTime,
|
"invalidTime": invalidTime,
|
||||||
};
|
};
|
||||||
if (scheduleList != null) {
|
if (scheduleList != null) {
|
||||||
body["scheduleList"] = scheduleList.map((schedule) => schedule.toJson()).toList();
|
body["scheduleList"] =
|
||||||
|
scheduleList.map((schedule) => schedule.toJson()).toList();
|
||||||
}
|
}
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.addTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
|
path: ApiEndpoints.addTemporaryPassword
|
||||||
|
.replaceAll('{doorLockUuid}', deviceId),
|
||||||
body: body,
|
body: body,
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) => json,
|
expectedResponseModel: (json) => json,
|
||||||
@ -229,7 +239,8 @@ class DevicesAPI {
|
|||||||
static Future generateOneTimePassword({deviceId}) async {
|
static Future generateOneTimePassword({deviceId}) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.addOneTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
|
path: ApiEndpoints.addOneTimeTemporaryPassword
|
||||||
|
.replaceAll('{doorLockUuid}', deviceId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json;
|
return json;
|
||||||
@ -241,10 +252,12 @@ class DevicesAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future generateMultiTimePassword({deviceId, effectiveTime, invalidTime}) async {
|
static Future generateMultiTimePassword(
|
||||||
|
{deviceId, effectiveTime, invalidTime}) async {
|
||||||
try {
|
try {
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.addMultipleTimeTemporaryPassword.replaceAll('{doorLockUuid}', deviceId),
|
path: ApiEndpoints.addMultipleTimeTemporaryPassword
|
||||||
|
.replaceAll('{doorLockUuid}', deviceId),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
body: {"effectiveTime": effectiveTime, "invalidTime": invalidTime},
|
body: {"effectiveTime": effectiveTime, "invalidTime": invalidTime},
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
|
@ -27,4 +27,5 @@ abstract class ColorsManager {
|
|||||||
static const Color red = Colors.red;
|
static const Color red = Colors.red;
|
||||||
static const Color graysColor = Color(0xffEBEBEB);
|
static const Color graysColor = Color(0xffEBEBEB);
|
||||||
static const Color textGray = Color(0xffD5D5D5);
|
static const Color textGray = Color(0xffD5D5D5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -618,3 +618,35 @@ List<Map<String, Object>> members = [
|
|||||||
'role': MemberRole.FamilyMember,
|
'role': MemberRole.FamilyMember,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
enum status {
|
||||||
|
on,
|
||||||
|
off,
|
||||||
|
restart,
|
||||||
|
}
|
||||||
|
|
||||||
|
extension StatusExtension on status {
|
||||||
|
String get value {
|
||||||
|
switch (this) {
|
||||||
|
case status.on:
|
||||||
|
return "Power Off";
|
||||||
|
case status.off:
|
||||||
|
return "Power On";
|
||||||
|
case status.restart:
|
||||||
|
return "Restart Memory";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static status fromString(String value) {
|
||||||
|
switch (value) {
|
||||||
|
case "power_off":
|
||||||
|
return status.off;
|
||||||
|
case "power_on":
|
||||||
|
return status.on;
|
||||||
|
case "last":
|
||||||
|
return status.restart;
|
||||||
|
default:
|
||||||
|
throw ArgumentError("Invalid access type: $value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user