diff --git a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart index efd0618..09ec737 100644 --- a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart +++ b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart @@ -1,6 +1,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart'; +import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; +import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/status_model.dart'; diff --git a/lib/features/devices/bloc/acs_bloc/acs_events.dart b/lib/features/devices/bloc/acs_bloc/acs_event.dart similarity index 100% rename from lib/features/devices/bloc/acs_bloc/acs_events.dart rename to lib/features/devices/bloc/acs_bloc/acs_event.dart diff --git a/lib/features/devices/bloc/acs_bloc/acs_state.dart b/lib/features/devices/bloc/acs_bloc/acs_state.dart index b6cba04..79288c2 100644 --- a/lib/features/devices/bloc/acs_bloc/acs_state.dart +++ b/lib/features/devices/bloc/acs_bloc/acs_state.dart @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:syncrow_app/features/devices/model/status_model.dart'; +import 'package:syncrow_app/features/devices/model/ac_model.dart'; abstract class AcsState extends Equatable { const AcsState(); diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart new file mode 100644 index 0000000..bedc531 --- /dev/null +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart @@ -0,0 +1,33 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart'; +import 'package:syncrow_app/features/devices/model/device_model.dart'; +import 'package:syncrow_app/features/devices/model/status_model.dart'; +import 'package:syncrow_app/features/devices/model/three_gang_model.dart'; +import 'package:syncrow_app/services/api/devices_api.dart'; + +class ThreeGangBloc extends Bloc { + final String threeGangId; + late DeviceModel deviceModel; + late ThreeGangModel deviceStatus; + + ThreeGangBloc({required this.threeGangId}) : super(InitialState()) { + on(_fetchThreeGangStatus); + } + + void _fetchThreeGangStatus(InitialEvent event, Emitter emit) async { + emit(LoadingState()); + try { + var response = await DevicesAPI.getDeviceStatus(threeGangId); + List statusModelList = []; + for (var status in response['status']) { + statusModelList.add(StatusModel.fromJson(status)); + } + deviceStatus = ThreeGangModel.fromJson(statusModelList); + emit(UpdateState(threeGangModel: deviceStatus)); + } catch (e) { + emit(FailedState(error: e.toString())); + return; + } + } +} diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart new file mode 100644 index 0000000..43fae5f --- /dev/null +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart @@ -0,0 +1,14 @@ +import 'package:equatable/equatable.dart'; + +abstract class ThreeGangEvent extends Equatable { + const ThreeGangEvent(); + + @override + List get props => []; +} + +class LoadingEvent extends ThreeGangEvent {} + +class InitialEvent extends ThreeGangEvent {} + +class ChangeStatusEvent extends ThreeGangEvent {} diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_state.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_state.dart new file mode 100644 index 0000000..d30f092 --- /dev/null +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_state.dart @@ -0,0 +1,30 @@ +import 'package:equatable/equatable.dart'; +import 'package:syncrow_app/features/devices/model/three_gang_model.dart'; + +class ThreeGangState extends Equatable { + const ThreeGangState(); + + @override + List get props => []; +} + +class InitialState extends ThreeGangState {} + +class LoadingState extends ThreeGangState {} + +class UpdateState extends ThreeGangState { + final ThreeGangModel threeGangModel; + const UpdateState({required this.threeGangModel}); + + @override + List get props => [threeGangModel]; +} + +class FailedState extends ThreeGangState { + final String error; + + const FailedState({required this.error}); + + @override + List get props => [error]; +} diff --git a/lib/features/devices/model/ac_model.dart b/lib/features/devices/model/ac_model.dart new file mode 100644 index 0000000..0106ad1 --- /dev/null +++ b/lib/features/devices/model/ac_model.dart @@ -0,0 +1,81 @@ +import 'package:syncrow_app/features/devices/model/status_model.dart'; +import 'package:syncrow_app/utils/resource_manager/constants.dart'; + +class AcStatusModel { + bool acSwitch; + String modeString; + int tempSet; + int currentTemp; + String fanSpeedsString; + bool childLock; + late TempModes acMode; + late FanSpeeds acFanSpeed; + + AcStatusModel( + {required this.acSwitch, + required this.modeString, + required this.tempSet, + required this.currentTemp, + required this.fanSpeedsString, + required this.childLock}) { + acMode = getACMode(modeString); + acFanSpeed = getFanSpeed(fanSpeedsString); + } + + factory AcStatusModel.fromJson(List jsonList) { + late bool _acSwitch; + late String _mode; + late int _tempSet; + late int _currentTemp; + late String _fanSpeeds; + late bool _childLock; + for (int i = 0; i < jsonList.length; i++) { + if (jsonList[i].code == 'switch') { + _acSwitch = jsonList[i].value ?? false; + } else if (jsonList[i].code == 'mode') { + _mode = jsonList[i].value ?? TempModes.cold; + } else if (jsonList[i].code == 'temp_set') { + _tempSet = jsonList[i].value ?? 210; + } else if (jsonList[i].code == 'temp_current') { + _currentTemp = jsonList[i].value ?? 210; + } else if (jsonList[i].code == 'level') { + _fanSpeeds = jsonList[i].value ?? 210; + } else if (jsonList[i].code == 'child_lock') { + _childLock = jsonList[i].value ?? false; + } + } + return AcStatusModel( + acSwitch: _acSwitch, + modeString: _mode, + tempSet: _tempSet, + currentTemp: _currentTemp, + fanSpeedsString: _fanSpeeds, + childLock: _childLock); + } + + static TempModes getACMode(String value) { + if (value == 'cold') { + return TempModes.cold; + } else if (value == 'hot') { + return TempModes.hot; + } else if (value == 'wind') { + return TempModes.wind; + } else { + return TempModes.cold; + } + } + + static FanSpeeds getFanSpeed(String value) { + if (value == 'low') { + return FanSpeeds.low; + } else if (value == 'middle') { + return FanSpeeds.middle; + } else if (value == 'high') { + return FanSpeeds.high; + } else if (value == 'auto') { + return FanSpeeds.auto; + } else { + return FanSpeeds.auto; + } + } +} diff --git a/lib/features/devices/model/status_model.dart b/lib/features/devices/model/status_model.dart index 6f8314b..0d22625 100644 --- a/lib/features/devices/model/status_model.dart +++ b/lib/features/devices/model/status_model.dart @@ -1,84 +1,3 @@ -import 'package:syncrow_app/utils/resource_manager/constants.dart'; - -class AcStatusModel { - bool acSwitch; - String modeString; - int tempSet; - int currentTemp; - String fanSpeedsString; - bool childLock; - late TempModes acMode; - late FanSpeeds acFanSpeed; - - AcStatusModel( - {required this.acSwitch, - required this.modeString, - required this.tempSet, - required this.currentTemp, - required this.fanSpeedsString, - required this.childLock}) { - acMode = getACMode(modeString); - acFanSpeed = getFanSpeed(fanSpeedsString); - } - - factory AcStatusModel.fromJson(List jsonList) { - late bool _acSwitch; - late String _mode; - late int _tempSet; - late int _currentTemp; - late String _fanSpeeds; - late bool _childLock; - for (int i = 0; i < jsonList.length; i++) { - if (jsonList[i].code == 'switch') { - _acSwitch = jsonList[i].value ?? false; - } else if (jsonList[i].code == 'mode') { - _mode = jsonList[i].value ?? TempModes.cold; - } else if (jsonList[i].code == 'temp_set') { - _tempSet = jsonList[i].value ?? 210; - } else if (jsonList[i].code == 'temp_current') { - _currentTemp = jsonList[i].value ?? 210; - } else if (jsonList[i].code == 'level') { - _fanSpeeds = jsonList[i].value ?? 210; - } else if (jsonList[i].code == 'child_lock') { - _childLock = jsonList[i].value ?? false; - } - } - return AcStatusModel( - acSwitch: _acSwitch, - modeString: _mode, - tempSet: _tempSet, - currentTemp: _currentTemp, - fanSpeedsString: _fanSpeeds, - childLock: _childLock); - } - - static TempModes getACMode(String value) { - if (value == 'cold') { - return TempModes.cold; - } else if (value == 'hot') { - return TempModes.hot; - } else if (value == 'wind') { - return TempModes.wind; - } else { - return TempModes.cold; - } - } - - static FanSpeeds getFanSpeed(String value) { - if (value == 'low') { - return FanSpeeds.low; - } else if (value == 'middle') { - return FanSpeeds.middle; - } else if (value == 'high') { - return FanSpeeds.high; - } else if (value == 'auto') { - return FanSpeeds.auto; - } else { - return FanSpeeds.auto; - } - } -} - class StatusModel { String? code; dynamic value; diff --git a/lib/features/devices/model/three_gang_model.dart b/lib/features/devices/model/three_gang_model.dart new file mode 100644 index 0000000..c862823 --- /dev/null +++ b/lib/features/devices/model/three_gang_model.dart @@ -0,0 +1,50 @@ +import 'package:syncrow_app/features/devices/model/status_model.dart'; + +class ThreeGangModel { + bool firstSwitch; + bool secondSwitch; + bool thirdSwitch; + int firstCountDown; + int secondCountDown; + int thirdCountDown; + + ThreeGangModel( + {required this.firstSwitch, + required this.secondSwitch, + required this.thirdSwitch, + required this.firstCountDown, + required this.secondCountDown, + required this.thirdCountDown}); + + factory ThreeGangModel.fromJson(List jsonList) { + late bool _firstSwitch; + late bool _secondSwitch; + late bool _thirdSwitch; + late int _firstCount; + late int _secondCount; + late int _thirdCount; + + for (int i = 0; i < jsonList.length; i++) { + if (jsonList[i].code == 'switch_1') { + _firstSwitch = jsonList[i].value ?? false; + } else if (jsonList[i].code == 'switch_2') { + _secondSwitch = jsonList[i].value ?? false; + } else if (jsonList[i].code == 'switch_3') { + _thirdSwitch = jsonList[i].value ?? false; + } else if (jsonList[i].code == 'countdown_1') { + _firstCount = jsonList[i].value ?? 0; + } else if (jsonList[i].code == 'countdown_2') { + _secondCount = jsonList[i].value ?? 0; + } else if (jsonList[i].code == 'countdown_3') { + _thirdCount = jsonList[i].value ?? 0; + } + } + return ThreeGangModel( + firstSwitch: _firstSwitch, + secondSwitch: _secondSwitch, + thirdSwitch: _thirdSwitch, + firstCountDown: _firstCount, + secondCountDown: _secondCount, + thirdCountDown: _thirdCount); + } +} diff --git a/lib/features/devices/view/widgets/ACs/ac_interface_controls.dart b/lib/features/devices/view/widgets/ACs/ac_interface_controls.dart index 74c63ab..8fe7d85 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface_controls.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface_controls.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart'; +import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart'; diff --git a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart index 8c71273..3ae38f8 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart @@ -3,7 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:sleek_circular_slider/sleek_circular_slider.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart'; +import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; diff --git a/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart b/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart index ba39f99..4e34f0e 100644 --- a/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart +++ b/lib/features/devices/view/widgets/ACs/ac_mode_control_unit.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart'; +import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; diff --git a/lib/features/devices/view/widgets/ACs/acs_view.dart b/lib/features/devices/view/widgets/ACs/acs_view.dart index b5db1da..63cafde 100644 --- a/lib/features/devices/view/widgets/ACs/acs_view.dart +++ b/lib/features/devices/view/widgets/ACs/acs_view.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart'; +import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart'; diff --git a/lib/features/devices/view/widgets/room_page_switch.dart b/lib/features/devices/view/widgets/room_page_switch.dart index 944b123..251d325 100644 --- a/lib/features/devices/view/widgets/room_page_switch.dart +++ b/lib/features/devices/view/widgets/room_page_switch.dart @@ -17,7 +17,6 @@ import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_ import 'package:syncrow_app/features/shared_widgets/custom_switch.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; -import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/helpers/custom_page_route.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; @@ -108,7 +107,12 @@ void showDeviceInterface(DeviceModel device, BuildContext context) { case DeviceType.LightBulb: navigateToInterface(LightInterface(light: device), context); case DeviceType.ThreeGang: - navigateToInterface(ThreeGangInterface(gangSwitch: device), context); + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, animation2) => + ThreeGangInterface(gangSwitch: device))); + // navigateToInterface(ThreeGangInterface(gangSwitch: device), context); break; default: } diff --git a/lib/features/devices/view/widgets/three_gang/gang_switch.dart b/lib/features/devices/view/widgets/three_gang/gang_switch.dart index 2c1dd60..33068fb 100644 --- a/lib/features/devices/view/widgets/three_gang/gang_switch.dart +++ b/lib/features/devices/view/widgets/three_gang/gang_switch.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; -import 'package:syncrow_app/features/devices/model/device_control_model.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; @@ -11,41 +11,35 @@ class GangSwitch extends StatelessWidget { const GangSwitch({ super.key, required this.threeGangSwitch, - required this.control, + required this.value, }); final DeviceModel threeGangSwitch; - final DeviceControlModel control; + final bool value; @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { return InkWell( overlayColor: MaterialStateProperty.all(Colors.transparent), onTap: () { - var tempControl = DeviceControlModel( - deviceId: control.deviceId, - code: control.code!, - value: !control.value!); - DevicesCubit.getInstance().deviceControl( - tempControl, - control.deviceId!, - ); + // var tempControl = DeviceControlModel( + // deviceId: control.deviceId, code: control.code!, value: !control.value!); + // DevicesCubit.getInstance().deviceControl( + // tempControl, + // control.deviceId!, + // ); }, child: Stack( - alignment: - !control.value! ? Alignment.topCenter : Alignment.bottomCenter, + alignment: value ? Alignment.topCenter : Alignment.bottomCenter, children: [ Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(100.0)), - color: threeGangSwitch.status - .firstWhere((element) => element.code == control.code) - .value! - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.switchOffColor, + color: + value ? ColorsManager.primaryColorWithOpacity : ColorsManager.switchOffColor, ), width: 60, height: 115, @@ -54,22 +48,10 @@ class GangSwitch extends StatelessWidget { padding: const EdgeInsets.all(5.0), child: SizedBox.square( dimension: 60, - child: state is GetDeviceStatusLoading && - state.code == control.code || - state is DeviceControlSuccess && - state.code == control.code || - state is DeviceControlLoading && - state.code == control.code - ? const SizedBox( - width: 10, - height: 10, - child: Center(child: CircularProgressIndicator())) - : SvgPicture.asset( - control.value! - ? Assets.assetsIconsLightSwitchOn - : Assets.assetsIconsLightSwitchOff, - fit: BoxFit.fill, - ), + child: SvgPicture.asset( + value ? Assets.assetsIconsLightSwitchOn : Assets.assetsIconsLightSwitchOff, + fit: BoxFit.fill, + ), ), ), ], diff --git a/lib/features/devices/view/widgets/three_gang/three_gang_interface.dart b/lib/features/devices/view/widgets/three_gang/three_gang_interface.dart index d343d9b..dd37fd2 100644 --- a/lib/features/devices/view/widgets/three_gang/three_gang_interface.dart +++ b/lib/features/devices/view/widgets/three_gang/three_gang_interface.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; -import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface_body.dart'; +import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_screen.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; @@ -53,7 +53,7 @@ class ThreeGangInterface extends StatelessWidget { right: Constants.defaultPadding, bottom: Constants.bottomNavBarHeight, ), - child: ThreeGangInterfaceBody( + child: ThreeGangScreen( device: gangSwitch, ), ), diff --git a/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart b/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart deleted file mode 100644 index 7b2cfdf..0000000 --- a/lib/features/devices/view/widgets/three_gang/three_gang_interface_body.dart +++ /dev/null @@ -1,328 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; -import 'package:syncrow_app/features/devices/model/device_control_model.dart'; -import 'package:syncrow_app/features/devices/model/device_model.dart'; -import 'package:syncrow_app/features/devices/view/widgets/three_gang/gang_switch.dart'; -import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; -import 'package:syncrow_app/utils/context_extension.dart'; -import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; - -class ThreeGangInterfaceBody extends StatelessWidget { - const ThreeGangInterfaceBody({ - super.key, - required this.device, - }); - - final DeviceModel device; - - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - const Expanded(child: SizedBox.shrink()), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Column( - children: [ - GangSwitch( - threeGangSwitch: device, - control: DeviceControlModel( - deviceId: device.uuid, - // code: 'switch_1', - code: device.status[0].code, - // value: true, - value: device.status[0].value, - ), - ), - const SizedBox(height: 20), - const SizedBox( - width: 70, - child: BodySmall( - text: "Bedside Light", - fontColor: ColorsManager.textPrimaryColor, - textAlign: TextAlign.center, - ), - ), - ], - ), - Column( - children: [ - GangSwitch( - threeGangSwitch: device, - control: DeviceControlModel( - // deviceId: 'bfe10693d4fd263206ocq9', - // code: 'switch_2', - // value: true, - deviceId: device.uuid, - code: device.status[1].code, - value: device.status[1].value, - ), - ), - const SizedBox(height: 20), - const SizedBox( - width: 70, - child: BodySmall( - text: "Ceiling Light", - fontColor: ColorsManager.textPrimaryColor, - textAlign: TextAlign.center, - ), - ), - ], - ), - Column( - children: [ - GangSwitch( - threeGangSwitch: device, - control: DeviceControlModel( - // deviceId: 'bfe10693d4fd263206ocq9', - // code: 'switch_3', - // value: true, - deviceId: device.uuid, - code: device.status[2].code, - value: device.status[2].value, - ), - ), - const SizedBox(height: 20), - const SizedBox( - width: 70, - child: BodySmall( - text: "Spotlight", - fontColor: ColorsManager.textPrimaryColor, - textAlign: TextAlign.center, - ), - ), - ], - ), - ], - ), - Expanded( - child: Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Column( - mainAxisSize: MainAxisSize.min, - children: [ - Card( - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), - ), - child: InkWell( - onTap: () { - DevicesCubit.getInstance().deviceControl( - DeviceControlModel( - deviceId: device.uuid, - code: 'switch_1', - value: true, - ), - device.uuid!, - ); - DevicesCubit.getInstance().deviceControl( - DeviceControlModel( - deviceId: device.uuid, - code: 'switch_2', - value: true, - ), - device.uuid!, - ); - DevicesCubit.getInstance().deviceControl( - DeviceControlModel( - deviceId: device.uuid, - code: 'switch_3', - value: true, - ), - device.uuid!, - ); - }, - child: Stack( - alignment: Alignment.center, - children: [ - Container( - width: 60, - height: 60, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(100), - ), - ), - Container( - width: 40, - height: 40, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(100), - ), - child: Center( - child: BodySmall( - text: "On", - style: context.bodyMedium.copyWith( - color: ColorsManager - .primaryColorWithOpacity, - fontWeight: FontWeight.bold), - ), - ), - ), - ], - ), - ), - ), - const SizedBox(height: 10), - BodySmall( - text: "All On", - style: context.bodyMedium.copyWith( - color: ColorsManager.textPrimaryColor, - ), - ), - ], - ), - const SizedBox( - width: 20, - ), - Column( - mainAxisSize: MainAxisSize.min, - children: [ - Card( - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), - ), - child: InkWell( - onTap: () {}, - child: Stack( - alignment: Alignment.center, - children: [ - Container( - width: 60, - height: 60, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(100), - ), - ), - Container( - width: 40, - height: 40, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(100), - ), - child: Center( - child: Icon( - Icons.access_time, - color: - ColorsManager.primaryColorWithOpacity, - size: 25, - ), - ), - ), - ], - ), - ), - ), - const SizedBox(height: 10), - BodySmall( - text: "Timer", - style: context.bodyMedium.copyWith( - color: ColorsManager.textPrimaryColor, - ), - ), - ], - ), - const SizedBox( - width: 20, - ), - Column( - mainAxisSize: MainAxisSize.min, - children: [ - Card( - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), - ), - child: InkWell( - onTap: () { - DevicesCubit.getInstance().deviceControl( - DeviceControlModel( - deviceId: device.uuid, - code: 'switch_1', - value: false, - ), - device.uuid!, - ); - DevicesCubit.getInstance().deviceControl( - DeviceControlModel( - deviceId: device.uuid, - code: 'switch_2', - value: false, - ), - device.uuid!, - ); - DevicesCubit.getInstance().deviceControl( - DeviceControlModel( - deviceId: device.uuid, - code: 'switch_3', - value: false, - ), - device.uuid!, - ); - }, - child: Stack( - alignment: Alignment.center, - children: [ - Container( - width: 60, - height: 60, - decoration: BoxDecoration( - color: Colors.grey[300], - borderRadius: BorderRadius.circular(100), - ), - ), - Container( - width: 40, - height: 40, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(100), - ), - child: Center( - child: BodySmall( - text: "Off", - style: context.bodyMedium.copyWith( - color: ColorsManager - .primaryColorWithOpacity, - fontWeight: FontWeight.bold), - ), - ), - ), - ], - ), - ), - ), - const SizedBox(height: 10), - BodySmall( - text: "All Off", - style: context.bodyMedium.copyWith( - color: ColorsManager.textPrimaryColor, - ), - ), - ], - ), - ], - ), - ), - ), - ], - ); - }, - ); - } -} diff --git a/lib/features/devices/view/widgets/three_gang/three_gang_screen.dart b/lib/features/devices/view/widgets/three_gang/three_gang_screen.dart new file mode 100644 index 0000000..e323d36 --- /dev/null +++ b/lib/features/devices/view/widgets/three_gang/three_gang_screen.dart @@ -0,0 +1,341 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart'; +import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart'; +import 'package:syncrow_app/features/devices/model/device_model.dart'; +import 'package:syncrow_app/features/devices/model/three_gang_model.dart'; +import 'package:syncrow_app/features/devices/view/widgets/three_gang/gang_switch.dart'; +import 'package:syncrow_app/features/shared_widgets/default_container.dart'; +import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; +import 'package:syncrow_app/utils/context_extension.dart'; +import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; + +class ThreeGangScreen extends StatelessWidget { + const ThreeGangScreen({ + super.key, + required this.device, + }); + + final DeviceModel device; + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => ThreeGangBloc(threeGangId: device.uuid ?? '')..add(InitialEvent()), + child: BlocBuilder( + builder: (context, state) { + ThreeGangModel threeGangModel = ThreeGangModel( + firstSwitch: false, + secondSwitch: false, + thirdSwitch: false, + firstCountDown: 0, + secondCountDown: 0, + thirdCountDown: 0); + if (state is UpdateState) { + threeGangModel = state.threeGangModel; + } + return state is LoadingState + ? const Center( + child: + DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()), + ) + : Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const Expanded(child: SizedBox.shrink()), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Column( + children: [ + GangSwitch( + threeGangSwitch: device, + value: threeGangModel.firstSwitch, + // control: DeviceControlModel( + // deviceId: device.uuid, + // // code: 'switch_1', + // code: device.status[0].code, + // // value: true, + // value: device.status[0].value, + // ), + ), + const SizedBox(height: 20), + const SizedBox( + width: 70, + child: BodySmall( + text: "Bedside Light", + fontColor: ColorsManager.textPrimaryColor, + textAlign: TextAlign.center, + ), + ), + ], + ), + Column( + children: [ + GangSwitch( + threeGangSwitch: device, + value: threeGangModel.secondSwitch, + // control: DeviceControlModel( + // // deviceId: 'bfe10693d4fd263206ocq9', + // // code: 'switch_2', + // // value: true, + // deviceId: device.uuid, + // code: device.status[1].code, + // value: device.status[1].value, + // ), + ), + const SizedBox(height: 20), + const SizedBox( + width: 70, + child: BodySmall( + text: "Ceiling Light", + fontColor: ColorsManager.textPrimaryColor, + textAlign: TextAlign.center, + ), + ), + ], + ), + Column( + children: [ + GangSwitch( + threeGangSwitch: device, + value: threeGangModel.thirdSwitch, + ), + const SizedBox(height: 20), + const SizedBox( + width: 70, + child: BodySmall( + text: "Spotlight", + fontColor: ColorsManager.textPrimaryColor, + textAlign: TextAlign.center, + ), + ), + ], + ), + ], + ), + Expanded( + child: Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(100), + ), + child: GestureDetector( + onTap: () { + // DevicesCubit.getInstance().deviceControl( + // DeviceControlModel( + // deviceId: device.uuid, + // code: 'switch_1', + // value: true, + // ), + // device.uuid!, + // ); + // DevicesCubit.getInstance().deviceControl( + // DeviceControlModel( + // deviceId: device.uuid, + // code: 'switch_2', + // value: true, + // ), + // device.uuid!, + // ); + // DevicesCubit.getInstance().deviceControl( + // DeviceControlModel( + // deviceId: device.uuid, + // code: 'switch_3', + // value: true, + // ), + // device.uuid!, + // ); + }, + child: Stack( + alignment: Alignment.center, + children: [ + Container( + width: 60, + height: 60, + decoration: BoxDecoration( + color: Colors.grey[300], + borderRadius: BorderRadius.circular(100), + ), + ), + Container( + width: 40, + height: 40, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(100), + ), + child: Center( + child: BodySmall( + text: "On", + style: context.bodyMedium.copyWith( + color: ColorsManager.primaryColorWithOpacity, + fontWeight: FontWeight.bold), + ), + ), + ), + ], + ), + ), + ), + const SizedBox(height: 10), + BodySmall( + text: "All On", + style: context.bodyMedium.copyWith( + color: ColorsManager.textPrimaryColor, + ), + ), + ], + ), + const SizedBox( + width: 20, + ), + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(100), + ), + child: GestureDetector( + onTap: () {}, + child: Stack( + alignment: Alignment.center, + children: [ + Container( + width: 60, + height: 60, + decoration: BoxDecoration( + color: Colors.grey[300], + borderRadius: BorderRadius.circular(100), + ), + ), + Container( + width: 40, + height: 40, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(100), + ), + child: Center( + child: Icon( + Icons.access_time, + color: ColorsManager.primaryColorWithOpacity, + size: 25, + ), + ), + ), + ], + ), + ), + ), + const SizedBox(height: 10), + BodySmall( + text: "Timer", + style: context.bodyMedium.copyWith( + color: ColorsManager.textPrimaryColor, + ), + ), + ], + ), + const SizedBox( + width: 20, + ), + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(100), + ), + child: GestureDetector( + onTap: () { + // DevicesCubit.getInstance().deviceControl( + // DeviceControlModel( + // deviceId: device.uuid, + // code: 'switch_1', + // value: false, + // ), + // device.uuid!, + // ); + // DevicesCubit.getInstance().deviceControl( + // DeviceControlModel( + // deviceId: device.uuid, + // code: 'switch_2', + // value: false, + // ), + // device.uuid!, + // ); + // DevicesCubit.getInstance().deviceControl( + // DeviceControlModel( + // deviceId: device.uuid, + // code: 'switch_3', + // value: false, + // ), + // device.uuid!, + // ); + }, + child: Stack( + alignment: Alignment.center, + children: [ + Container( + width: 60, + height: 60, + decoration: BoxDecoration( + color: Colors.grey[300], + borderRadius: BorderRadius.circular(100), + ), + ), + Container( + width: 40, + height: 40, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(100), + ), + child: Center( + child: BodySmall( + text: "Off", + style: context.bodyMedium.copyWith( + color: ColorsManager.primaryColorWithOpacity, + fontWeight: FontWeight.bold), + ), + ), + ), + ], + ), + ), + ), + const SizedBox(height: 10), + BodySmall( + text: "All Off", + style: context.bodyMedium.copyWith( + color: ColorsManager.textPrimaryColor, + ), + ), + ], + ), + ], + ), + ), + ), + ], + ); + }, + ), + ); + } +}