From 465a2e3108038c60db29bdcf5a0b7219fa1e59e0 Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 9 Oct 2024 14:58:08 +0300 Subject: [PATCH] curtain wizard & bugs fixes --- .../bloc/curtain_bloc/curtain_bloc.dart | 57 +++++++------------ .../bloc/curtain_bloc/curtain_event.dart | 2 +- .../garage_door_bloc/garage_door_bloc.dart | 3 +- .../bloc/water_leak_bloc/water_leak_bloc.dart | 12 +--- lib/features/devices/model/curtain_model.dart | 9 ++- .../devices/view/widgets/ACs/acs_list.dart | 2 + .../view/widgets/curtains/curtains_list.dart | 10 ++-- .../garage_door/garage_door_screen.dart | 17 ------ .../view/widgets/garage_door/garage_list.dart | 4 ++ .../garage_preferences_settings.dart | 7 +-- .../view/widgets/lights/lights_list.dart | 2 + .../view/widgets/one_gang/one_gang_list.dart | 4 ++ .../view/widgets/one_touch/one_gang_list.dart | 7 ++- .../widgets/three_gang/three_gang_list.dart | 49 +++++++++++----- .../widgets/three_touch/three_touch_list.dart | 50 +++++++++++----- .../view/widgets/two_gang/two_gang_list.dart | 6 ++ .../widgets/two_touch/two_touch_list.dart | 9 ++- .../view/widgets/water_heater/wh_list.dart | 4 ++ .../devices_default_switch.dart | 8 ++- lib/services/api/devices_api.dart | 9 +-- lib/utils/resource_manager/constants.dart | 2 +- pubspec.yaml | 2 +- 22 files changed, 158 insertions(+), 117 deletions(-) diff --git a/lib/features/devices/bloc/curtain_bloc/curtain_bloc.dart b/lib/features/devices/bloc/curtain_bloc/curtain_bloc.dart index 15571e5..6de8d58 100644 --- a/lib/features/devices/bloc/curtain_bloc/curtain_bloc.dart +++ b/lib/features/devices/bloc/curtain_bloc/curtain_bloc.dart @@ -27,7 +27,7 @@ class CurtainBloc extends Bloc { on(_onCloseCurtain); on(_onPauseCurtain); on(_changeFirstWizardSwitch); - on(_fetchOneTouchWizardStatus); + on(_fetchWizardStatus); on(_groupAllOff); on(_groupAllOn); } @@ -187,12 +187,11 @@ class CurtainBloc extends Bloc { List groupList = []; bool allSwitchesOn = true; List devicesList = []; - CurtainModel deviceStatus = CurtainModel( - control: 'stop', - ); - void _fetchOneTouchWizardStatus( + CurtainModel deviceStatus = CurtainModel(control: 'stop', percent: 0); + void _fetchWizardStatus( InitialWizardEvent event, Emitter emit) async { - emit(CurtainLoadingState()); + emit(LoadingInitialState()); + try { devicesList = []; groupList = []; @@ -212,14 +211,14 @@ class CurtainBloc extends Bloc { deviceId: devicesList[i].uuid ?? '', deviceName: devicesList[i].name ?? '', firstSwitch: deviceStatus.control, - percentControl: 0)); + percentControl: deviceStatus.percent)); } if (groupList.isNotEmpty) { groupList.firstWhere((element) { - print('object=====${element.firstSwitch}'); - if (element.firstSwitch == 'close') { - allSwitchesOn = false; + print('object=====${element.percentControl}'); + if (element.percentControl > 1) { + allSwitchesOn = true; } return true; }); @@ -241,15 +240,16 @@ class CurtainBloc extends Bloc { // Update the firstSwitch value in the groupList based on the deviceId groupList.forEach((element) { if (element.deviceId == event.deviceId) { - element.firstSwitch = event.value; // Set the new value from the event + element.percentControl = + event.value; // Set the new value from the event } - if (element.firstSwitch != 'open') { - allSwitchesValue = false; // Check if any switch is not 'open' + if (element.percentControl > 1) { + allSwitchesValue = true; // Check if any switch is not 'open' } }); final response = await DevicesAPI.deviceBatchController( - code: 'control', + code: 'percent_control', devicesUuid: [event.deviceId], value: event.value, // Use the value from the event ); @@ -268,9 +268,8 @@ class CurtainBloc extends Bloc { void _groupAllOn(GroupAllOnEvent event, Emitter emit) async { emit(LoadingNewSate(curtainModel: deviceStatus)); try { - // Set all devices to 'open' for (int i = 0; i < groupList.length; i++) { - groupList[i].firstSwitch = 'open'; + groupList[i].percentControl = 100; } emit(UpdateGroupState(curtainList: groupList, allSwitches: true)); @@ -278,19 +277,13 @@ class CurtainBloc extends Bloc { List allDeviceIds = groupList.map((device) => device.deviceId).toList(); - final response1 = await DevicesAPI.deviceBatchController( - code: 'control', - devicesUuid: allDeviceIds, - value: 'open', // Set the devices to 'open' - ); - final response2 = await DevicesAPI.deviceBatchController( - code: 'control', + code: 'percent_control', devicesUuid: allDeviceIds, - value: 'open', + value: 100, ); - if (response1['failedResults'].toString() != '[]') { + if (response2['failedResults'].toString() != '[]') { await Future.delayed(const Duration(milliseconds: 500)); // Handle retry or error if needed. } @@ -306,7 +299,7 @@ class CurtainBloc extends Bloc { try { // Set all devices to 'close' for (int i = 0; i < groupList.length; i++) { - groupList[i].firstSwitch = 'close'; + groupList[i].percentControl = 0; } emit(UpdateGroupState(curtainList: groupList, allSwitches: false)); @@ -314,19 +307,13 @@ class CurtainBloc extends Bloc { List allDeviceIds = groupList.map((device) => device.deviceId).toList(); - final response1 = await DevicesAPI.deviceBatchController( - code: 'control', - devicesUuid: allDeviceIds, - value: 'close', // Set the devices to 'close' - ); - final response2 = await DevicesAPI.deviceBatchController( - code: 'control', + code: 'percent_control', devicesUuid: allDeviceIds, - value: 'close', + value: 0, ); - if (response1['failedResults'].toString() != '[]') { + if (response2['failedResults'].toString() != '[]') { await Future.delayed(const Duration(milliseconds: 500)); // Handle retry or error if needed. } diff --git a/lib/features/devices/bloc/curtain_bloc/curtain_event.dart b/lib/features/devices/bloc/curtain_bloc/curtain_event.dart index 11b7d9e..4ee52e3 100644 --- a/lib/features/devices/bloc/curtain_bloc/curtain_event.dart +++ b/lib/features/devices/bloc/curtain_bloc/curtain_event.dart @@ -36,7 +36,7 @@ class InitialWizardEvent extends CurtainEvent {} class ChangeFirstWizardSwitchStatusEvent extends CurtainEvent { - final String value; + final int value; final String deviceId; const ChangeFirstWizardSwitchStatusEvent( {required this.value, this.deviceId = ''}); diff --git a/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart b/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart index d4aa759..686e272 100644 --- a/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart +++ b/lib/features/devices/bloc/garage_door_bloc/garage_door_bloc.dart @@ -41,6 +41,7 @@ class GarageDoorBloc extends Bloc { on(_groupAllOff); on(_changeFirstWizardSwitch); on(_toggleAlarmEvent); + on(deleteSchedule); //_toggleAlarmEvent } void _onClose(OnClose event, Emitter emit) { @@ -167,7 +168,7 @@ class GarageDoorBloc extends Bloc { startTime: startTime.toString(), endTime: endTime.toString(), deviceUuid: GDId, - code: 'doorcontact_state', + code: 'switch_1', ); recordGroups = response; emit(UpdateState(garageSensor: deviceStatus)); diff --git a/lib/features/devices/bloc/water_leak_bloc/water_leak_bloc.dart b/lib/features/devices/bloc/water_leak_bloc/water_leak_bloc.dart index 688afc4..300c4f4 100644 --- a/lib/features/devices/bloc/water_leak_bloc/water_leak_bloc.dart +++ b/lib/features/devices/bloc/water_leak_bloc/water_leak_bloc.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:dio/dio.dart'; import 'package:firebase_database/firebase_database.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_event.dart'; import 'package:syncrow_app/features/devices/bloc/water_leak_bloc/water_leak_state.dart'; @@ -51,15 +50,12 @@ class WaterLeakBloc extends Bloc { } } - // Toggle functions for each switch void _toggleLowBattery( ToggleLowBatteryEvent event, Emitter emit) async { emit(LoadingNewSate(waterSensor: deviceStatus)); try { lowBattery = event.isLowBatteryEnabled; emit(UpdateState(waterSensor: deviceStatus)); - - // API call to update the state, if necessary await DevicesAPI.controlDevice( DeviceControlModel( deviceId: WLId, @@ -100,8 +96,6 @@ class WaterLeakBloc extends Bloc { try { waterAlarm = event.isWaterLeakAlarmEnabled; emit(UpdateState(waterSensor: deviceStatus)); - - // API call to update the state, if necessary await DevicesAPI.controlDevice( DeviceControlModel( deviceId: WLId, @@ -120,7 +114,6 @@ class WaterLeakBloc extends Bloc { Future fetchLogsForLastMonth( ReportLogsInitial event, Emitter emit) async { - // Get the current date and time DateTime now = DateTime.now(); DateTime lastMonth = DateTime(now.year, now.month - 1, now.day); int startTime = lastMonth.millisecondsSinceEpoch; @@ -131,17 +124,14 @@ class WaterLeakBloc extends Bloc { startTime: startTime.toString(), endTime: endTime.toString(), deviceUuid: WLId, - code: 'watercontact_state', + code: 'watersensor_state', ); recordGroups = response; emit(UpdateState(waterSensor: deviceStatus)); } on DioException catch (e) { final errorData = e.response!.data; String errorMessage = errorData['message']; - // Handle error emit(WaterLeakFailedState(errorMessage: errorMessage)); - - debugPrint('Error fetching logs: ${errorMessage}'); } } diff --git a/lib/features/devices/model/curtain_model.dart b/lib/features/devices/model/curtain_model.dart index 4150613..a8cf3e5 100644 --- a/lib/features/devices/model/curtain_model.dart +++ b/lib/features/devices/model/curtain_model.dart @@ -2,21 +2,28 @@ import 'package:syncrow_app/features/devices/model/status_model.dart'; class CurtainModel { String control; + int percent; CurtainModel({ required this.control, + required this.percent, }); factory CurtainModel.fromJson(List jsonList) { late String _control; - + late int _percent; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'control') { _control = jsonList[i].value ?? false; } + if (jsonList[i].code == 'percent_control') { + _percent = jsonList[i].value ?? 0; + } } + //percent_control return CurtainModel( control: _control, + percent: _percent, ); } } diff --git a/lib/features/devices/view/widgets/ACs/acs_list.dart b/lib/features/devices/view/widgets/ACs/acs_list.dart index e58f679..735bc9c 100644 --- a/lib/features/devices/view/widgets/ACs/acs_list.dart +++ b/lib/features/devices/view/widgets/ACs/acs_list.dart @@ -86,6 +86,8 @@ class ACsList extends StatelessWidget { ), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: devicesStatuesList[index].acSwitch, action: () { BlocProvider.of(context).add(AcSwitch( diff --git a/lib/features/devices/view/widgets/curtains/curtains_list.dart b/lib/features/devices/view/widgets/curtains/curtains_list.dart index d09b2e0..28a22da 100644 --- a/lib/features/devices/view/widgets/curtains/curtains_list.dart +++ b/lib/features/devices/view/widgets/curtains/curtains_list.dart @@ -28,6 +28,8 @@ class CurtainsList extends StatelessWidget { const BodySmall(text: 'All Curtains'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'Close', + on: 'Open', switchValue: allSwitches, action: () { BlocProvider.of(context).add(GroupAllOnEvent()); @@ -49,13 +51,13 @@ class CurtainsList extends StatelessWidget { BodySmall(text: curtainsList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( - switchValue: curtainsList[index].firstSwitch == 'open', + off: 'close', + on: 'open', + switchValue: curtainsList[index].percentControl > 1, action: () { // Toggle between 'open' and 'close' based on current value final newValue = - curtainsList[index].firstSwitch == 'open' - ? 'close' - : 'open'; + curtainsList[index].percentControl > 1 ? 0 : 100; BlocProvider.of(context).add( ChangeFirstWizardSwitchStatusEvent( value: newValue, diff --git a/lib/features/devices/view/widgets/garage_door/garage_door_screen.dart b/lib/features/devices/view/widgets/garage_door/garage_door_screen.dart index ae1fe0d..78639d8 100644 --- a/lib/features/devices/view/widgets/garage_door/garage_door_screen.dart +++ b/lib/features/devices/view/widgets/garage_door/garage_door_screen.dart @@ -29,23 +29,6 @@ class GarageDoorScreen extends StatelessWidget { child: BlocBuilder( builder: (context, state) { final garageBloc = BlocProvider.of(context); - // GarageDoorModel model = GarageDoorModel( - // tr_timecon: 0, - // countdown1: 0, - // countdownAlarm: 0, - // doorContactState: false, - // doorControl1: '', - // doorState1: '', - // switch1: false, - // voiceControl1: false, - // batteryPercentage: 0, - // ); - - // if (state is LoadingNewSate) { - // model = state.doorSensor; - // } else if (state is UpdateState) { - // model = state.garageSensor; - // } return state is GarageDoorLoadingState ? const Center( child: diff --git a/lib/features/devices/view/widgets/garage_door/garage_list.dart b/lib/features/devices/view/widgets/garage_door/garage_list.dart index b3d3f81..4ddef1b 100644 --- a/lib/features/devices/view/widgets/garage_door/garage_list.dart +++ b/lib/features/devices/view/widgets/garage_door/garage_list.dart @@ -26,6 +26,8 @@ class GarageList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { BlocProvider.of(context) @@ -49,6 +51,8 @@ class GarageList extends StatelessWidget { BodySmall(text: garageList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: garageList[index].firstSwitch, action: () { BlocProvider.of(context).add( diff --git a/lib/features/devices/view/widgets/garage_door/garage_preferences_settings.dart b/lib/features/devices/view/widgets/garage_door/garage_preferences_settings.dart index 8aa81a9..185d003 100644 --- a/lib/features/devices/view/widgets/garage_door/garage_preferences_settings.dart +++ b/lib/features/devices/view/widgets/garage_door/garage_preferences_settings.dart @@ -97,12 +97,9 @@ class PreferencesPage extends StatelessWidget { Transform.scale( scale: .8, child: CupertinoSwitch( - value: garageDoorBloc.deviceStatus - .doorState1 == - 'unclosed_time', + value: garageDoorBloc.deviceStatus.doorState1 != 'unclosed_time', onChanged: (value) { - context - .read() + context.read() .add( ToggleAlarmEvent( value diff --git a/lib/features/devices/view/widgets/lights/lights_list.dart b/lib/features/devices/view/widgets/lights/lights_list.dart index aafc372..1d4be63 100644 --- a/lib/features/devices/view/widgets/lights/lights_list.dart +++ b/lib/features/devices/view/widgets/lights/lights_list.dart @@ -48,6 +48,8 @@ class LightsList extends StatelessWidget { ), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: false, action: () {}, ), diff --git a/lib/features/devices/view/widgets/one_gang/one_gang_list.dart b/lib/features/devices/view/widgets/one_gang/one_gang_list.dart index abf3c4b..b30077f 100644 --- a/lib/features/devices/view/widgets/one_gang/one_gang_list.dart +++ b/lib/features/devices/view/widgets/one_gang/one_gang_list.dart @@ -26,6 +26,8 @@ class OneGangList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { BlocProvider.of(context).add(GroupAllOnEvent()); @@ -47,6 +49,8 @@ class OneGangList extends StatelessWidget { BodySmall(text: oneGangList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: oneGangList[index].firstSwitch, action: () { BlocProvider.of(context).add( diff --git a/lib/features/devices/view/widgets/one_touch/one_gang_list.dart b/lib/features/devices/view/widgets/one_touch/one_gang_list.dart index 9f0fc11..b1ab484 100644 --- a/lib/features/devices/view/widgets/one_touch/one_gang_list.dart +++ b/lib/features/devices/view/widgets/one_touch/one_gang_list.dart @@ -27,12 +27,15 @@ class OneTouchList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { BlocProvider.of(context).add(GroupAllOnEvent()); }, secondAction: () { - BlocProvider.of(context).add(GroupAllOffEvent()); + BlocProvider.of(context) + .add(GroupAllOffEvent()); }, ), ListView.builder( @@ -48,6 +51,8 @@ class OneTouchList extends StatelessWidget { BodySmall(text: oneTouchList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: oneTouchList[index].firstSwitch, action: () { BlocProvider.of(context).add( diff --git a/lib/features/devices/view/widgets/three_gang/three_gang_list.dart b/lib/features/devices/view/widgets/three_gang/three_gang_list.dart index 0d9b143..d556296 100644 --- a/lib/features/devices/view/widgets/three_gang/three_gang_list.dart +++ b/lib/features/devices/view/widgets/three_gang/three_gang_list.dart @@ -8,7 +8,8 @@ import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart' import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; class ThreeGangList extends StatelessWidget { - const ThreeGangList({super.key, required this.threeGangList, required this.allSwitches}); + const ThreeGangList( + {super.key, required this.threeGangList, required this.allSwitches}); final List threeGangList; final bool allSwitches; @@ -25,12 +26,16 @@ class ThreeGangList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { - BlocProvider.of(context).add(GroupAllOnEvent()); + BlocProvider.of(context) + .add(GroupAllOnEvent()); }, secondAction: () { - BlocProvider.of(context).add(GroupAllOffEvent()); + BlocProvider.of(context) + .add(GroupAllOffEvent()); }, ), ListView.builder( @@ -43,36 +48,50 @@ class ThreeGangList extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 10), - BodySmall(text: '${threeGangList[index].deviceName} beside light'), + BodySmall( + text: + '${threeGangList[index].deviceName} beside light'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: threeGangList[index].firstSwitch, action: () { - BlocProvider.of(context).add(ChangeFirstSwitchStatusEvent( - value: threeGangList[index].firstSwitch, - deviceId: threeGangList[index].deviceId)); + BlocProvider.of(context).add( + ChangeFirstSwitchStatusEvent( + value: threeGangList[index].firstSwitch, + deviceId: threeGangList[index].deviceId)); }, ), const SizedBox(height: 10), - BodySmall(text: '${threeGangList[index].deviceName} ceiling light'), + BodySmall( + text: + '${threeGangList[index].deviceName} ceiling light'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: threeGangList[index].secondSwitch, action: () { - BlocProvider.of(context).add(ChangeSecondSwitchStatusEvent( - value: threeGangList[index].secondSwitch, - deviceId: threeGangList[index].deviceId)); + BlocProvider.of(context).add( + ChangeSecondSwitchStatusEvent( + value: threeGangList[index].secondSwitch, + deviceId: threeGangList[index].deviceId)); }, ), const SizedBox(height: 10), - BodySmall(text: '${threeGangList[index].deviceName} spotlight'), + BodySmall( + text: '${threeGangList[index].deviceName} spotlight'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: threeGangList[index].thirdSwitch, action: () { - BlocProvider.of(context).add(ChangeThirdSwitchStatusEvent( - value: threeGangList[index].thirdSwitch, - deviceId: threeGangList[index].deviceId)); + BlocProvider.of(context).add( + ChangeThirdSwitchStatusEvent( + value: threeGangList[index].thirdSwitch, + deviceId: threeGangList[index].deviceId)); }, ), ], diff --git a/lib/features/devices/view/widgets/three_touch/three_touch_list.dart b/lib/features/devices/view/widgets/three_touch/three_touch_list.dart index aed2946..245ae08 100644 --- a/lib/features/devices/view/widgets/three_touch/three_touch_list.dart +++ b/lib/features/devices/view/widgets/three_touch/three_touch_list.dart @@ -8,7 +8,8 @@ import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart' import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; class ThreeTouchList extends StatelessWidget { - const ThreeTouchList({super.key, required this.threeTouchList, required this.allSwitches}); + const ThreeTouchList( + {super.key, required this.threeTouchList, required this.allSwitches}); final List threeTouchList; final bool allSwitches; @@ -25,12 +26,16 @@ class ThreeTouchList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { - BlocProvider.of(context).add(GroupAllOnEvent()); + BlocProvider.of(context) + .add(GroupAllOnEvent()); }, secondAction: () { - BlocProvider.of(context).add(GroupAllOffEvent()); + BlocProvider.of(context) + .add(GroupAllOffEvent()); }, ), ListView.builder( @@ -43,36 +48,51 @@ class ThreeTouchList extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 10), - BodySmall(text: '${threeTouchList[index].deviceName} beside light'), + BodySmall( + text: + '${threeTouchList[index].deviceName} beside light'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: threeTouchList[index].firstSwitch, action: () { - BlocProvider.of(context).add(ChangeFirstSwitchStatusEvent( - value: threeTouchList[index].firstSwitch, - deviceId: threeTouchList[index].deviceId)); + BlocProvider.of(context).add( + ChangeFirstSwitchStatusEvent( + value: threeTouchList[index].firstSwitch, + deviceId: threeTouchList[index].deviceId)); }, ), const SizedBox(height: 10), - BodySmall(text: '${threeTouchList[index].deviceName} ceiling light'), + BodySmall( + text: + '${threeTouchList[index].deviceName} ceiling light'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: threeTouchList[index].secondSwitch, action: () { - BlocProvider.of(context).add(ChangeSecondSwitchStatusEvent( - value: threeTouchList[index].secondSwitch, - deviceId: threeTouchList[index].deviceId)); + BlocProvider.of(context).add( + ChangeSecondSwitchStatusEvent( + value: threeTouchList[index].secondSwitch, + deviceId: threeTouchList[index].deviceId)); }, ), const SizedBox(height: 10), - BodySmall(text: '${threeTouchList[index].deviceName} spotlight'), + BodySmall( + text: + '${threeTouchList[index].deviceName} spotlight'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: threeTouchList[index].thirdSwitch, action: () { - BlocProvider.of(context).add(ChangeThirdSwitchStatusEvent( - value: threeTouchList[index].thirdSwitch, - deviceId: threeTouchList[index].deviceId)); + BlocProvider.of(context).add( + ChangeThirdSwitchStatusEvent( + value: threeTouchList[index].thirdSwitch, + deviceId: threeTouchList[index].deviceId)); }, ), ], diff --git a/lib/features/devices/view/widgets/two_gang/two_gang_list.dart b/lib/features/devices/view/widgets/two_gang/two_gang_list.dart index d0c4d78..0da995e 100644 --- a/lib/features/devices/view/widgets/two_gang/two_gang_list.dart +++ b/lib/features/devices/view/widgets/two_gang/two_gang_list.dart @@ -26,6 +26,8 @@ class TwoGangList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { BlocProvider.of(context).add(GroupAllOnEvent()); @@ -47,6 +49,8 @@ class TwoGangList extends StatelessWidget { BodySmall(text: twoGangList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: twoGangList[index].firstSwitch, action: () { BlocProvider.of(context).add( @@ -59,6 +63,8 @@ class TwoGangList extends StatelessWidget { BodySmall(text: twoGangList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: twoGangList[index].secondSwitch, action: () { BlocProvider.of(context).add( diff --git a/lib/features/devices/view/widgets/two_touch/two_touch_list.dart b/lib/features/devices/view/widgets/two_touch/two_touch_list.dart index ebc5c14..4537da6 100644 --- a/lib/features/devices/view/widgets/two_touch/two_touch_list.dart +++ b/lib/features/devices/view/widgets/two_touch/two_touch_list.dart @@ -26,12 +26,15 @@ class TwoTouchList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { BlocProvider.of(context).add(GroupAllOnEvent()); }, secondAction: () { - BlocProvider.of(context).add(GroupAllOffEvent()); + BlocProvider.of(context) + .add(GroupAllOffEvent()); }, ), ListView.builder( @@ -47,6 +50,8 @@ class TwoTouchList extends StatelessWidget { BodySmall(text: twoTouchList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: twoTouchList[index].firstSwitch, action: () { BlocProvider.of(context).add( @@ -59,6 +64,8 @@ class TwoTouchList extends StatelessWidget { BodySmall(text: twoTouchList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: twoTouchList[index].secondSwitch, action: () { BlocProvider.of(context).add( diff --git a/lib/features/devices/view/widgets/water_heater/wh_list.dart b/lib/features/devices/view/widgets/water_heater/wh_list.dart index ace29e5..ebc2ddd 100644 --- a/lib/features/devices/view/widgets/water_heater/wh_list.dart +++ b/lib/features/devices/view/widgets/water_heater/wh_list.dart @@ -25,6 +25,8 @@ class WHList extends StatelessWidget { const BodySmall(text: 'All Lights'), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: allSwitches, action: () { BlocProvider.of(context) @@ -48,6 +50,8 @@ class WHList extends StatelessWidget { BodySmall(text: whList[index].deviceName), const SizedBox(height: 5), DevicesDefaultSwitch( + off: 'OFF', + on: 'ON', switchValue: whList[index].firstSwitch, action: () { BlocProvider.of(context).add( diff --git a/lib/features/shared_widgets/devices_default_switch.dart b/lib/features/shared_widgets/devices_default_switch.dart index f31fb50..b0783fc 100644 --- a/lib/features/shared_widgets/devices_default_switch.dart +++ b/lib/features/shared_widgets/devices_default_switch.dart @@ -7,9 +7,13 @@ class DevicesDefaultSwitch extends StatelessWidget { {super.key, required this.switchValue, required this.action, + required this.on, + required this.off, this.secondAction}); final bool switchValue; + final String on; + final String off; final Function action; final Function? secondAction; @@ -36,7 +40,7 @@ class DevicesDefaultSwitch extends StatelessWidget { child: Center( child: BodyMedium( fontSize: 14, - text: "ON", + text: on, fontColor: switchValue ? Colors.white : null, fontWeight: FontWeight.w700, ), @@ -67,7 +71,7 @@ class DevicesDefaultSwitch extends StatelessWidget { child: Center( child: BodyMedium( fontSize: 14, - text: "OFF", + text: off, fontColor: switchValue ? null : Colors.white, fontWeight: FontWeight.w700, ), diff --git a/lib/services/api/devices_api.dart b/lib/services/api/devices_api.dart index 7186eb6..c2d7e34 100644 --- a/lib/services/api/devices_api.dart +++ b/lib/services/api/devices_api.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:developer'; import 'package:syncrow_app/features/devices/model/device_category_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; @@ -60,11 +61,8 @@ class DevicesAPI { } static Future> fetchGroups(String spaceId) async { - // Map params = {"homeId": spaceId, "pageSize": 100, "pageNo": 1}; - final response = await _httpService.get( path: ApiEndpoints.groupBySpace.replaceAll('{unitUuid}', spaceId), - // queryParameters: params, showServerMessage: false, expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json), ); @@ -72,12 +70,12 @@ class DevicesAPI { } static Future> getDeviceStatus(String deviceId) async { + print(deviceId); final response = await _httpService.get( path: ApiEndpoints.deviceFunctionsStatus .replaceAll('{deviceUuid}', deviceId), showServerMessage: false, expectedResponseModel: (json) { - print('json======${json}'); return json; }, ); @@ -124,6 +122,7 @@ class DevicesAPI { return []; } List devices = []; + for (var device in json) { devices.add(DeviceModel.fromJson(device)); } @@ -386,13 +385,11 @@ class DevicesAPI { String? code, var value, }) async { - print({"devicesUuid": devicesUuid, "code": code, "value": value}); final response = await _httpService.post( path: ApiEndpoints.controlBatch, body: {"devicesUuid": devicesUuid, "code": code, "value": value}, showServerMessage: true, expectedResponseModel: (json) { - print('json-=-=-=-=-=-${json}'); return json; }, ); diff --git a/lib/utils/resource_manager/constants.dart b/lib/utils/resource_manager/constants.dart index e76100e..4542cba 100644 --- a/lib/utils/resource_manager/constants.dart +++ b/lib/utils/resource_manager/constants.dart @@ -815,7 +815,7 @@ extension lightStatusExtension on lightStatus { case lightStatus.switchPosition: return "On/Off Status"; case lightStatus.on_off: - return "Restart Memory"; + return "Switch Position"; } } diff --git a/pubspec.yaml b/pubspec.yaml index 920357b..1d80b6f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.4+27 +version: 1.0.4+28 environment: sdk: ">=3.0.6 <4.0.0"