diff --git a/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart b/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart index 061dbca..db30079 100644 --- a/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart +++ b/lib/features/devices/bloc/one_gang_bloc/one_gang_bloc.dart @@ -35,10 +35,12 @@ class OneGangBloc extends Bloc { on(_onClose); on(toggleDaySelection); - on(saveSchedule); + on(saveSchedule); on(getSchedule); on(toggleChange); on(deleteSchedule); + on(toggleSelectedIndex); + on(toggleCreateSchedule); } void _fetchOneGangStatus(InitialEvent event, Emitter emit) async { @@ -196,7 +198,7 @@ class OneGangBloc extends Bloc { ]; Future saveSchedule( - ThreeGangSave event, + ScheduleSave event, Emitter emit, ) async { try { @@ -211,8 +213,9 @@ class OneGangBloc extends Bloc { days: selectedDays); CustomSnackBar.displaySnackBar('Save Successfully'); add(GetScheduleEvent()); - emit(ThreeGangSaveSchedule()); - toggleCreateSchedule(); + emit(SaveSchedule()); + + add(const ToggleCreateScheduleEvent(index:1 )); } else { CustomSnackBar.displaySnackBar('Please select days'); } @@ -287,14 +290,23 @@ class OneGangBloc extends Bloc { } } - void toggleCreateSchedule() { - emit(LoadingInitialState()); - createSchedule = !createSchedule; - selectedDays.clear(); - selectedTime = DateTime.now(); - emit(UpdateCreateScheduleState(createSchedule)); - emit(ChangeSlidingSegmentState(value: 1)); - } + // void toggleCreateSchedule() { + // emit(LoadingInitialState()); + // createSchedule = !createSchedule; + // selectedDays.clear(); + // selectedTime = DateTime.now(); + // emit(UpdateCreateScheduleState(createSchedule)); + // emit(ChangeSlidingSegmentState(value: 1)); + // } + + + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { + emit(LoadingInitialState()); + createSchedule = !createSchedule; + selectedDays.clear(); + selectedTime = DateTime.now(); + emit(UpdateCreateScheduleState(createSchedule)); +} bool toggleSchedule = true; List selectedDays = []; @@ -317,9 +329,9 @@ class OneGangBloc extends Bloc { int selectedTabIndex = 0; - void toggleSelectedIndex(index) { + void toggleSelectedIndex( ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); - selectedTabIndex = index; + selectedTabIndex =event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } } diff --git a/lib/features/devices/bloc/one_gang_bloc/one_gang_event.dart b/lib/features/devices/bloc/one_gang_bloc/one_gang_event.dart index af6dee2..a59f653 100644 --- a/lib/features/devices/bloc/one_gang_bloc/one_gang_event.dart +++ b/lib/features/devices/bloc/one_gang_bloc/one_gang_event.dart @@ -92,7 +92,7 @@ class OnClose extends OneGangEvent {} //------------------- Schedule ----------=--------- class GetScheduleEvent extends OneGangEvent {} -class ThreeGangSave extends OneGangEvent {} +class ScheduleSave extends OneGangEvent {} class ToggleScheduleEvent extends OneGangEvent { final String id; final bool toggle; @@ -114,3 +114,19 @@ class DeleteScheduleEvent extends OneGangEvent { @override List get props => [id]; } + + +class ToggleSelectedEvent extends OneGangEvent { + final int index; + const ToggleSelectedEvent({required this.index}); + @override + List get props => [index]; +} + + +class ToggleCreateScheduleEvent extends OneGangEvent { + final int index; + const ToggleCreateScheduleEvent({required this.index}); + @override + List get props => [index]; +} diff --git a/lib/features/devices/bloc/one_gang_bloc/one_gang_state.dart b/lib/features/devices/bloc/one_gang_bloc/one_gang_state.dart index 4078ccf..693851d 100644 --- a/lib/features/devices/bloc/one_gang_bloc/one_gang_state.dart +++ b/lib/features/devices/bloc/one_gang_bloc/one_gang_state.dart @@ -77,7 +77,7 @@ class TimerRunInProgress extends OneGangState { class TimerRunComplete extends OneGangState {} -class ThreeGangSaveSchedule extends OneGangState {} +class SaveSchedule extends OneGangState {} class IsToggleState extends OneGangState { final bool? onOff; 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 index 2822b1b..1985acd 100644 --- a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart @@ -55,6 +55,9 @@ class ThreeGangBloc extends Bloc { on(getSchedule); on(toggleChange); on(deleteSchedule); + + on(toggleSelectedIndex); + on(toggleCreateSchedule); } void _fetchThreeGangStatus(InitialEvent event, Emitter emit) async { @@ -528,7 +531,7 @@ class ThreeGangBloc extends Bloc { CustomSnackBar.displaySnackBar('Save Successfully'); add(GetScheduleEvent()); emit(ThreeGangSaveSchedule()); - toggleCreateSchedule(); + add(const ToggleCreateScheduleEvent(index:1 )); } else { CustomSnackBar.displaySnackBar('Please select days'); } @@ -603,23 +606,40 @@ class ThreeGangBloc extends Bloc { } } - void toggleCreateSchedule() { - emit(LoadingInitialState()); - createSchedule = !createSchedule; - selectedDays.clear(); - selectedTime = DateTime.now(); - emit(UpdateCreateScheduleState(createSchedule)); - emit(ChangeSlidingSegmentState(value: 1)); - } + // void toggleCreateSchedule() { + // emit(LoadingInitialState()); + // createSchedule = !createSchedule; + // selectedDays.clear(); + // selectedTime = DateTime.now(); + // emit(UpdateCreateScheduleState(createSchedule)); + // emit(ChangeSlidingSegmentState(value: 1)); + // } - int selectedTabIndex = 0; - void toggleSelectedIndex(index) { + + // void toggleSelectedIndex(index) { + // emit(LoadingInitialState()); + // selectedTabIndex = index; + // emit(ChangeSlidingSegmentState(value: selectedTabIndex)); + // } + + + void toggleSelectedIndex( ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); - selectedTabIndex = index; + selectedTabIndex =event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { + emit(LoadingInitialState()); + createSchedule = !createSchedule; + selectedDays.clear(); + selectedTime = DateTime.now(); + emit(UpdateCreateScheduleState(createSchedule)); +} + + + int selectedTabIndex = 0; bool toggleSchedule = true; List selectedDays = []; bool createSchedule = false; 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 index 89ad267..12e727b 100644 --- a/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_event.dart @@ -119,3 +119,20 @@ class DeleteScheduleEvent extends ThreeGangEvent { @override List get props => [id]; } + + + +class ToggleSelectedEvent extends ThreeGangEvent { + final int index; + const ToggleSelectedEvent({required this.index}); + @override + List get props => [index]; +} + + +class ToggleCreateScheduleEvent extends ThreeGangEvent { + final int index; + const ToggleCreateScheduleEvent({required this.index}); + @override + List get props => [index]; +} \ No newline at end of file diff --git a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart index bb1c329..0891db2 100644 --- a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart +++ b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart @@ -35,7 +35,8 @@ class TwoGangBloc extends Bloc { bool createSchedule = false; List listSchedule = []; - TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) { + TwoGangBloc({required this.twoGangId, required this.switchCode}) + : super(InitialState()) { on(_fetchTwoGangStatus); on(_twoGangUpdated); on(_changeFirstSwitch); @@ -54,28 +55,47 @@ class TwoGangBloc extends Bloc { on(getSchedule); on(toggleRepeat); on(deleteSchedule); + on(toggleSelectedIndex); + on(toggleCreateSchedule); } DateTime? selectedTime = DateTime.now(); - void toggleCreateSchedule() { + // void toggleCreateSchedule() { + // emit(LoadingInitialState()); + // createSchedule = !createSchedule; + // selectedDays.clear(); + // selectedTime = DateTime.now(); + // emit(UpdateCreateScheduleState(createSchedule)); + // emit(ChangeSlidingSegmentState(value: 1)); + // } + + int selectedTabIndex = 0; + + // void toggleSelectedIndex(index) { + // emit(LoadingInitialState()); + // selectedTabIndex = index; + // emit(ChangeSlidingSegmentState(value: selectedTabIndex)); + // } + + void toggleSelectedIndex( + ToggleSelectedEvent event, Emitter emit) { + emit(LoadingInitialState()); + selectedTabIndex = event.index; + emit(ChangeSlidingSegmentState(value: selectedTabIndex)); + } + + void toggleCreateSchedule( + ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); createSchedule = !createSchedule; selectedDays.clear(); selectedTime = DateTime.now(); emit(UpdateCreateScheduleState(createSchedule)); - emit(ChangeSlidingSegmentState(value: 1)); } - int selectedTabIndex = 0; - - void toggleSelectedIndex(index) { - emit(LoadingInitialState()); - selectedTabIndex = index; - emit(ChangeSlidingSegmentState(value: selectedTabIndex)); - } - - void _fetchTwoGangStatus(InitialEvent event, Emitter emit) async { + void _fetchTwoGangStatus( + InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { twoGangGroup = event.groupScreen; @@ -87,7 +107,8 @@ class TwoGangBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', '2G'); 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 statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -110,7 +131,8 @@ class TwoGangBloc extends Bloc { return true; }); } - emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState( + twoGangList: groupTwoGangList, allSwitches: allSwitchesOn)); } else { var response = await DevicesAPI.getDeviceStatus(twoGangId); List statusModelList = []; @@ -129,18 +151,21 @@ class TwoGangBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId'); + DatabaseReference ref = + FirebaseDatabase.instance.ref('device-status/$twoGangId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } - Map usersMap = event.snapshot.value as Map; + Map usersMap = + event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList.add(StatusModel(code: element['code'], value: element['value'])); + statusList + .add(StatusModel(code: element['code'], value: element['value'])); }); deviceStatus = TwoGangModel.fromJson(statusList); @@ -155,7 +180,8 @@ class TwoGangBloc extends Bloc { emit(UpdateState(twoGangModel: deviceStatus)); } - void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async { + void _changeFirstSwitch( + ChangeFirstSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { deviceStatus.firstSwitch = !event.value; @@ -181,7 +207,8 @@ class TwoGangBloc extends Bloc { } } - void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter emit) async { + void _changeSecondSwitch( + ChangeSecondSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { deviceStatus.secondSwitch = !event.value; @@ -217,11 +244,15 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch), + deviceId: twoGangId, + code: 'switch_1', + value: deviceStatus.firstSwitch), twoGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch), + deviceId: twoGangId, + code: 'switch_2', + value: deviceStatus.secondSwitch), twoGangId), ]); @@ -244,11 +275,15 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch), + deviceId: twoGangId, + code: 'switch_1', + value: deviceStatus.firstSwitch), twoGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch), + deviceId: twoGangId, + code: 'switch_2', + value: deviceStatus.secondSwitch), twoGangId), ]); if (response.every((element) => !element['success'])) { @@ -274,11 +309,15 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: groupTwoGangList[i].deviceId, code: 'switch_1', value: true), + deviceId: groupTwoGangList[i].deviceId, + code: 'switch_1', + value: true), groupTwoGangList[i].deviceId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: groupTwoGangList[i].deviceId, code: 'switch_2', value: true), + deviceId: groupTwoGangList[i].deviceId, + code: 'switch_2', + value: true), groupTwoGangList[i].deviceId), ]); @@ -307,11 +346,15 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: groupTwoGangList[i].deviceId, code: 'switch_1', value: false), + deviceId: groupTwoGangList[i].deviceId, + code: 'switch_1', + value: false), groupTwoGangList[i].deviceId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: groupTwoGangList[i].deviceId, code: 'switch_2', value: false), + deviceId: groupTwoGangList[i].deviceId, + code: 'switch_2', + value: false), groupTwoGangList[i].deviceId), ]); @@ -327,17 +370,20 @@ class TwoGangBloc extends Bloc { } } - void _changeSliding(ChangeSlidingSegment event, Emitter emit) async { + void _changeSliding( + ChangeSlidingSegment event, Emitter emit) async { emit(ChangeSlidingSegmentState(value: event.value)); } - void _setCounterValue(SetCounterValue event, Emitter emit) async { + void _setCounterValue( + SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds), + DeviceControlModel( + deviceId: twoGangId, code: event.deviceCode, value: seconds), twoGangId); if (response['success'] ?? false) { @@ -362,7 +408,8 @@ class TwoGangBloc extends Bloc { } } - void _getCounterValue(GetCounterEvent event, Emitter emit) async { + void _getCounterValue( + GetCounterEvent event, Emitter emit) async { emit(LoadingInitialState()); try { add(GetScheduleEvent()); @@ -449,7 +496,8 @@ class TwoGangBloc extends Bloc { CustomSnackBar.displaySnackBar('Save Successfully'); add(GetScheduleEvent()); emit(TwoGangSaveSchedule()); - toggleCreateSchedule(); + add(const ToggleCreateScheduleEvent(index: 1)); + // toggleCreateSchedule(); } else { CustomSnackBar.displaySnackBar('Please select days'); } @@ -469,7 +517,8 @@ class TwoGangBloc extends Bloc { deviceId: twoGangId, ); List jsonData = response; - listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = + jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(InitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -480,12 +529,13 @@ class TwoGangBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = - DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, + dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleRepeat(ToggleScheduleEvent event, Emitter emit) async { + Future toggleRepeat( + ToggleScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.changeSchedule( @@ -504,7 +554,8 @@ class TwoGangBloc extends Bloc { } } - Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule( + DeleteScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.deleteSchedule( diff --git a/lib/features/devices/bloc/two_gang_bloc/two_gang_event.dart b/lib/features/devices/bloc/two_gang_bloc/two_gang_event.dart index 9fd4737..db8bd96 100644 --- a/lib/features/devices/bloc/two_gang_bloc/two_gang_event.dart +++ b/lib/features/devices/bloc/two_gang_bloc/two_gang_event.dart @@ -62,7 +62,7 @@ class GroupAllOffEvent extends TwoGangEvent {} // two_gang_event.dart -class ToggleCreateScheduleEvent extends TwoGangEvent {} +// class ToggleCreateScheduleEvent extends TwoGangEvent {} @@ -125,6 +125,20 @@ class TabChangedEvent extends TwoGangEvent { } +class ToggleSelectedEvent extends TwoGangEvent { + final int index; + const ToggleSelectedEvent({required this.index}); + @override + List get props => [index]; +} + + +class ToggleCreateScheduleEvent extends TwoGangEvent { + final int index; + const ToggleCreateScheduleEvent({required this.index}); + @override + List get props => [index]; +} diff --git a/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart b/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart index 3a397c0..78e25ec 100644 --- a/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart +++ b/lib/features/devices/bloc/water_heater_bloc/water_heater_bloc.dart @@ -48,6 +48,9 @@ class WaterHeaterBloc extends Bloc { on(_onTickTimer); on(_onClose); on(showTime); + + on(toggleSelectedIndex); + on(toggleCreateSchedule); } void _fetchWaterHeaterStatus(WaterHeaterInitial event, Emitter emit) async { @@ -201,7 +204,7 @@ class WaterHeaterBloc extends Bloc { CustomSnackBar.displaySnackBar('Save Successfully'); add(GetScheduleEvent()); emit(SaveSchedule()); - toggleCreateSchedule(); + add(const ToggleCreateScheduleEvent(index:1 )); }else{ CustomSnackBar.displaySnackBar('Please select days'); } @@ -272,22 +275,43 @@ class WaterHeaterBloc extends Bloc { } } - void toggleCreateSchedule() { - emit(WHLoadingState()); - createSchedule = !createSchedule; - selectedDays.clear(); - selectedTime=DateTime.now(); - emit(UpdateCreateScheduleState(createSchedule)); - } + // void toggleCreateSchedule() { + // emit(WHLoadingState()); + // createSchedule = !createSchedule; + // selectedDays.clear(); + // selectedTime=DateTime.now(); + // emit(UpdateCreateScheduleState(createSchedule)); + // } void toggleCreateCirculate() { - emit(WHLoadingState()); + emit(WHLoadingState()); createCirculate = !createCirculate; selectedDays.clear(); selectedTime=DateTime.now(); emit(UpdateCreateScheduleState(createCirculate)); } + + // void toggleSelectedIndex(index) { + // emit(WHLoadingState()); + // selectedTabIndex = index; + // emit(ChangeSlidingSegmentState(value: selectedTabIndex)); + // } + void toggleSelectedIndex( ToggleSelectedEvent event, Emitter emit) { + emit(WHLoadingState()); + selectedTabIndex =event.index; + emit(ChangeSlidingSegmentState(value: selectedTabIndex)); + } + + + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { + emit(WHLoadingState()); + createSchedule = !createSchedule; + selectedDays.clear(); + selectedTime = DateTime.now(); + emit(UpdateCreateScheduleState(createSchedule)); +} + Future toggleDaySelection( ToggleDaySelectionEvent event, Emitter emit, @@ -303,11 +327,6 @@ class WaterHeaterBloc extends Bloc { int selectedTabIndex = 0; - void toggleSelectedIndex(index) { - emit(WHLoadingState()); - selectedTabIndex = index; - emit(ChangeSlidingSegmentState(value: selectedTabIndex)); - } showTime(SelectTimeEvent event, Emitter emit) async { final TimeOfDay? timePicked = await showTimePicker( diff --git a/lib/features/devices/bloc/water_heater_bloc/water_heater_event.dart b/lib/features/devices/bloc/water_heater_bloc/water_heater_event.dart index a0f8ef9..d39efa9 100644 --- a/lib/features/devices/bloc/water_heater_bloc/water_heater_event.dart +++ b/lib/features/devices/bloc/water_heater_bloc/water_heater_event.dart @@ -98,4 +98,28 @@ class SelectTimeEvent extends WaterHeaterEvent { const SelectTimeEvent({required this.context, required this.isEffective}); @override List get props => [context, isEffective]; -} \ No newline at end of file +} + + +class ToggleSelectedEvent extends WaterHeaterEvent { + final int index; + const ToggleSelectedEvent({required this.index}); + @override + List get props => [index]; +} + + +class ToggleCreateScheduleEvent extends WaterHeaterEvent { + final int index; + const ToggleCreateScheduleEvent({required this.index}); + @override + List get props => [index]; +} + + +class ToggleCreateCirculateEvent extends WaterHeaterEvent { + final int index; + const ToggleCreateCirculateEvent({required this.index}); + @override + List get props => [index]; +} diff --git a/lib/features/devices/view/widgets/one_gang/one_gang_screen.dart b/lib/features/devices/view/widgets/one_gang/one_gang_screen.dart index 59ffb34..2bc3353 100644 --- a/lib/features/devices/view/widgets/one_gang/one_gang_screen.dart +++ b/lib/features/devices/view/widgets/one_gang/one_gang_screen.dart @@ -22,8 +22,9 @@ class OneGangScreen extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => OneGangBloc(switchCode: 'switch_1', oneGangId: device?.uuid ?? '') - ..add(const InitialEvent(groupScreen: false)), + create: (context) => + OneGangBloc(switchCode: 'switch_1', oneGangId: device?.uuid ?? '') + ..add(const InitialEvent(groupScreen: false)), child: BlocBuilder( builder: (context, state) { OneGangModel oneGangModel = OneGangModel( @@ -44,15 +45,19 @@ class OneGangScreen extends StatelessWidget { } return state is LoadingInitialState ? const Center( - child: - DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()), + child: DefaultContainer( + width: 50, + height: 50, + child: CircularProgressIndicator()), ) : device == null - ? OneGangList(oneGangList: groupOneGangModel, allSwitches: allSwitchesOn) + ? OneGangList( + oneGangList: groupOneGangModel, + allSwitches: allSwitchesOn) : RefreshIndicator( onRefresh: () async { - BlocProvider.of(context) - .add(InitialEvent(groupScreen: device != null ? false : true)); + BlocProvider.of(context).add(InitialEvent( + groupScreen: device != null ? false : true)); }, child: ListView( children: [ @@ -65,8 +70,10 @@ class OneGangScreen extends StatelessWidget { const Expanded(child: SizedBox.shrink()), Expanded( child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: + MainAxisAlignment.spaceAround, + crossAxisAlignment: + CrossAxisAlignment.center, children: [ Column( children: [ @@ -74,9 +81,12 @@ class OneGangScreen extends StatelessWidget { threeGangSwitch: device!, value: oneGangModel.firstSwitch, action: () { - BlocProvider.of(context).add( - ChangeFirstSwitchStatusEvent( - value: oneGangModel.firstSwitch)); + BlocProvider.of( + context) + .add( + ChangeFirstSwitchStatusEvent( + value: oneGangModel + .firstSwitch)); }, ), const SizedBox(height: 20), @@ -84,7 +94,8 @@ class OneGangScreen extends StatelessWidget { width: 70, child: BodySmall( text: " Entrance Light", - fontColor: ColorsManager.textPrimaryColor, + fontColor: ColorsManager + .textPrimaryColor, textAlign: TextAlign.center, ), ), @@ -96,31 +107,33 @@ class OneGangScreen extends StatelessWidget { Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, children: [ - const SizedBox( - width: 20, - ), Column( mainAxisSize: MainAxisSize.min, children: [ Card( elevation: 3, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(100), + borderRadius: + BorderRadius.circular(100), ), child: GestureDetector( onTap: () { Navigator.push( context, PageRouteBuilder( - pageBuilder: - (context, animation1, animation2) => - TimerScheduleScreen( - switchCode: 'switch_1', - device: device!, - deviceCode: 'countdown_1', - ))); + pageBuilder: (context, + animation1, + animation2) => + TimerScheduleScreen( + switchCode: + 'switch_1', + device: device!, + deviceCode: + 'countdown_1', + ))); }, child: Stack( alignment: Alignment.center, @@ -130,7 +143,9 @@ class OneGangScreen extends StatelessWidget { height: 60, decoration: BoxDecoration( color: Colors.grey[300], - borderRadius: BorderRadius.circular(100), + borderRadius: + BorderRadius.circular( + 100), ), ), Container( @@ -138,13 +153,15 @@ class OneGangScreen extends StatelessWidget { height: 40, decoration: BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.circular(100), + borderRadius: + BorderRadius.circular( + 100), ), child: Center( child: Icon( Icons.access_time, - color: - ColorsManager.primaryColorWithOpacity, + color: ColorsManager + .primaryColorWithOpacity, size: 25, ), ), @@ -157,7 +174,8 @@ class OneGangScreen extends StatelessWidget { BodySmall( text: "Timer", style: context.bodyMedium.copyWith( - color: ColorsManager.textPrimaryColor, + color: ColorsManager + .textPrimaryColor, ), ), ], diff --git a/lib/features/devices/view/widgets/one_gang/one_gang_timer_screen.dart b/lib/features/devices/view/widgets/one_gang/one_gang_timer_screen.dart index 605d5d5..37676a0 100644 --- a/lib/features/devices/view/widgets/one_gang/one_gang_timer_screen.dart +++ b/lib/features/devices/view/widgets/one_gang/one_gang_timer_screen.dart @@ -17,16 +17,15 @@ import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/font_manager.dart'; - class TimerScheduleScreen extends StatelessWidget { final DeviceModel device; final String deviceCode; final String switchCode; const TimerScheduleScreen( {required this.device, - required this.deviceCode, - required this.switchCode, - super.key}); + required this.deviceCode, + required this.switchCode, + super.key}); @override Widget build(BuildContext context) { @@ -37,9 +36,9 @@ class TimerScheduleScreen extends StatelessWidget { ), child: BlocProvider( create: (context) => - OneGangBloc(switchCode: switchCode, oneGangId: device.uuid ?? '') - ..add(GetCounterEvent(deviceCode: deviceCode)) - ..add(GetScheduleEvent()), + OneGangBloc(switchCode: switchCode, oneGangId: device.uuid ?? '') + ..add(GetCounterEvent(deviceCode: deviceCode)) + ..add(GetScheduleEvent()), child: BlocBuilder( builder: (context, state) { final oneGangBloc = BlocProvider.of(context); @@ -64,7 +63,7 @@ class TimerScheduleScreen extends StatelessWidget { }, child: DefaultTabController( length: 2, - child: DefaultScaffold( + child: DefaultScaffold( appBar: AppBar( backgroundColor: Colors.transparent, centerTitle: true, @@ -74,175 +73,211 @@ class TimerScheduleScreen extends StatelessWidget { fontWeight: FontsManager.bold, ), actions: [ - oneGangBloc.createSchedule == true ? - TextButton( - onPressed: () { - oneGangBloc.add(ThreeGangSave()); - }, - child: const Text('Save') - ) : - oneGangBloc.selectedTabIndex==1? IconButton( - onPressed: () { - oneGangBloc.toggleCreateSchedule(); - }, - icon: const Icon(Icons.add), - ):SizedBox(), + oneGangBloc.createSchedule == true + ? TextButton( + onPressed: () { + oneGangBloc.add(ScheduleSave()); + }, + child: const Text('Save')) + : oneGangBloc.selectedTabIndex == 1 + ? IconButton( + onPressed: () { + // oneGangBloc.toggleCreateSchedule(); + oneGangBloc.add( + const ToggleCreateScheduleEvent( + index: 1)); + }, + icon: const Icon(Icons.add), + ) + : const SizedBox(), ], ), - child: - state is LoadingInitialState? - const Center(child: CircularProgressIndicator()): - Column( - children: [ - Container( - width: MediaQuery.of(context).size.width, - decoration: const ShapeDecoration( - color: ColorsManager.onPrimaryColor, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(30)), - ), - ), - child: TabBar( - onTap: (value) { - if(value==0){ - if(oneGangBloc.createSchedule == true){ - oneGangBloc.toggleCreateSchedule(); - } - oneGangBloc.toggleSelectedIndex(0); - }else{ - oneGangBloc.toggleSelectedIndex(1); - } - }, - indicatorColor: Colors.white, // Customize the indicator - dividerHeight: 0, - indicatorSize: TabBarIndicatorSize.tab, - indicator: const ShapeDecoration( - color: ColorsManager.slidingBlueColor, - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.all(Radius.circular(20)), - ), - ), - tabs: [ - Tab( - child: Container( - padding: const EdgeInsets.symmetric( - vertical: 10), - child: BodySmall( - text: 'Countdown', - style: context.bodySmall.copyWith( - color: ColorsManager.blackColor, - fontSize: 12, - fontWeight: FontWeight.w400, - ), - ), - ), - ), - Tab( - child: Container( - padding: const EdgeInsets.symmetric(vertical: 10), - child: Text( - 'Schedule', - style: context.bodySmall.copyWith( - color: ColorsManager.blackColor, - fontSize: 12, - fontWeight: FontWeight.w400, - ), - ), - ), - ), - ], - ), - ), - Expanded( - child: TabBarView( + child: state is LoadingInitialState + ? const Center(child: CircularProgressIndicator()) + : Column( children: [ - Center( - child: Container( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - countNum > 0 - ? BodyLarge( - text: _formatDuration(countNum), - fontColor: - ColorsManager.slidingBlueColor, - fontSize: 40, - ) - : CupertinoTimerPicker( - mode: CupertinoTimerPickerMode.hm, - onTimerDurationChanged: - (Duration newDuration) { - duration = newDuration; - }, - ), - GestureDetector( - onTap: () { - if (state is LoadingNewSate) { - return; - } - if (countNum > 0) { - oneGangBloc.add(SetCounterValue( - deviceCode: deviceCode, - duration: Duration.zero)); - } else if (duration != Duration.zero) { - oneGangBloc.add(SetCounterValue( - deviceCode: deviceCode, - duration: duration)); - } - }, - child: SvgPicture.asset(countNum > 0 - ? Assets.pauseIcon - : Assets.playIcon)), - ], + Container( + width: MediaQuery.of(context).size.width, + decoration: const ShapeDecoration( + color: ColorsManager.onPrimaryColor, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.all(Radius.circular(30)), ), ), - ), - Column( - mainAxisAlignment:oneGangBloc.listSchedule.isNotEmpty? - MainAxisAlignment.start:MainAxisAlignment.center, - children: [ - SizedBox( - child: oneGangBloc.createSchedule == true ? - CreateSchedule( - onToggleChanged: (bool isOn) { - oneGangBloc.toggleSchedule = isOn; - }, - onDateTimeChanged: (DateTime dateTime) { - oneGangBloc.selectedTime=dateTime; - }, - days: oneGangBloc.days, - selectDays: (List selectedDays) { - oneGangBloc.selectedDays = selectedDays; - }, - ) - : - Padding( - padding: const EdgeInsets.only(top: 10), - child: ScheduleListView( - listSchedule: oneGangBloc.listSchedule, // Pass the schedule list here - onDismissed: (scheduleId) { - oneGangBloc.listSchedule.removeWhere((schedule) => schedule.scheduleId == scheduleId); - oneGangBloc.add(DeleteScheduleEvent(id: scheduleId)); - }, - onToggleSchedule: (scheduleId, isEnabled) { - oneGangBloc.add(ToggleScheduleEvent( - id: scheduleId, - toggle: isEnabled, - )); - }, - ), + child: TabBar( + onTap: (value) { + if (value == 0) { + if (oneGangBloc.createSchedule == + true) { + // oneGangBloc.toggleCreateSchedule(); + oneGangBloc.add( + const ToggleCreateScheduleEvent( + index: 0)); + } + oneGangBloc.add( + const ToggleSelectedEvent( + index: 0)); + } else { + oneGangBloc.add( + const ToggleSelectedEvent( + index: 1)); + } + }, + indicatorColor: + Colors.white, // Customize the indicator + dividerHeight: 0, + indicatorSize: TabBarIndicatorSize.tab, + indicator: const ShapeDecoration( + color: ColorsManager.slidingBlueColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(20)), ), ), - ], + tabs: [ + Tab( + child: Container( + padding: const EdgeInsets.symmetric( + vertical: 10), + child: BodySmall( + text: 'Countdown', + style: context.bodySmall.copyWith( + color: ColorsManager.blackColor, + fontSize: 12, + fontWeight: FontWeight.w400, + ), + ), + ), + ), + Tab( + child: Container( + padding: const EdgeInsets.symmetric( + vertical: 10), + child: Text( + 'Schedule', + style: context.bodySmall.copyWith( + color: ColorsManager.blackColor, + fontSize: 12, + fontWeight: FontWeight.w400, + ), + ), + ), + ), + ], + ), + ), + Expanded( + child: TabBarView( + children: [ + Center( + child: Container( + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + countNum > 0 + ? BodyLarge( + text: _formatDuration( + countNum), + fontColor: ColorsManager + .slidingBlueColor, + fontSize: 40, + ) + : CupertinoTimerPicker( + mode: + CupertinoTimerPickerMode + .hm, + onTimerDurationChanged: + (Duration + newDuration) { + duration = newDuration; + }, + ), + GestureDetector( + onTap: () { + if (state + is LoadingNewSate) { + return; + } + if (countNum > 0) { + oneGangBloc.add( + SetCounterValue( + deviceCode: + deviceCode, + duration: Duration + .zero)); + } else if (duration != + Duration.zero) { + oneGangBloc.add( + SetCounterValue( + deviceCode: + deviceCode, + duration: + duration)); + } + }, + child: SvgPicture.asset( + countNum > 0 + ? Assets.pauseIcon + : Assets.playIcon)), + ], + ), + ), + ), + SizedBox( + child: oneGangBloc.createSchedule == + true + ? CreateSchedule( + onToggleChanged: (bool isOn) { + oneGangBloc.toggleSchedule = + isOn; + }, + onDateTimeChanged: + (DateTime dateTime) { + oneGangBloc.selectedTime = + dateTime; + }, + days: oneGangBloc.days, + selectDays: (List + selectedDays) { + oneGangBloc.selectedDays = + selectedDays; + }, + ) + : Padding( + padding: const EdgeInsets.only( + top: 10), + child: ScheduleListView( + listSchedule: oneGangBloc + .listSchedule, // Pass the schedule list here + onDismissed: (scheduleId) { + oneGangBloc.listSchedule + .removeWhere((schedule) => + schedule + .scheduleId == + scheduleId); + oneGangBloc.add( + DeleteScheduleEvent( + id: scheduleId)); + }, + onToggleSchedule: + (scheduleId, isEnabled) { + oneGangBloc.add( + ToggleScheduleEvent( + id: scheduleId, + toggle: isEnabled, + )); + }, + ), + ), + ), + ], + ), ), ], ), - ), - ], - ), - )) - ); + ))); }, ), ), diff --git a/lib/features/devices/view/widgets/three_gang/timer_screen.dart b/lib/features/devices/view/widgets/three_gang/timer_screen.dart index eb486f4..453c0e6 100644 --- a/lib/features/devices/view/widgets/three_gang/timer_screen.dart +++ b/lib/features/devices/view/widgets/three_gang/timer_screen.dart @@ -82,11 +82,14 @@ class TimerScheduleScreen extends StatelessWidget { : threeGangBloc.selectedTabIndex == 1 ? IconButton( onPressed: () { - threeGangBloc.toggleCreateSchedule(); + // oneGangBloc.toggleCreateSchedule(); + threeGangBloc.add( + const ToggleCreateScheduleEvent( + index: 1)); }, icon: const Icon(Icons.add), ) - : SizedBox(), + : const SizedBox(), ], ), child: state is LoadingInitialState @@ -103,15 +106,34 @@ class TimerScheduleScreen extends StatelessWidget { ), ), child: TabBar( + // onTap: (value) { + // if (value == 0) { + // if (threeGangBloc.createSchedule == + // true) { + // threeGangBloc.toggleCreateSchedule(); + // } + // threeGangBloc.toggleSelectedIndex(0); + // } else { + // threeGangBloc.toggleSelectedIndex(1); + // } + // }, + onTap: (value) { if (value == 0) { if (threeGangBloc.createSchedule == true) { - threeGangBloc.toggleCreateSchedule(); + // oneGangBloc.toggleCreateSchedule(); + threeGangBloc.add( + const ToggleCreateScheduleEvent( + index: 0)); } - threeGangBloc.toggleSelectedIndex(0); + threeGangBloc.add( + const ToggleSelectedEvent( + index: 0)); } else { - threeGangBloc.toggleSelectedIndex(1); + threeGangBloc.add( + const ToggleSelectedEvent( + index: 1)); } }, indicatorColor: Colors.white, diff --git a/lib/features/devices/view/widgets/two_gang/two_timer_screen.dart b/lib/features/devices/view/widgets/two_gang/two_timer_screen.dart index fcdf71c..9aa7abc 100644 --- a/lib/features/devices/view/widgets/two_gang/two_timer_screen.dart +++ b/lib/features/devices/view/widgets/two_gang/two_timer_screen.dart @@ -82,11 +82,14 @@ class TimerScheduleScreen extends StatelessWidget { : twoGangBloc.selectedTabIndex == 1 ? IconButton( onPressed: () { - twoGangBloc.toggleCreateSchedule(); + // oneGangBloc.toggleCreateSchedule(); + twoGangBloc.add( + const ToggleCreateScheduleEvent( + index: 1)); }, icon: const Icon(Icons.add), ) - : SizedBox(), + : const SizedBox(), ], ), child: state is LoadingInitialState @@ -104,15 +107,21 @@ class TimerScheduleScreen extends StatelessWidget { ), child: TabBar( onTap: (value) { - print(value); if (value == 0) { if (twoGangBloc.createSchedule == true) { - twoGangBloc.toggleCreateSchedule(); + // oneGangBloc.toggleCreateSchedule(); + twoGangBloc.add( + const ToggleCreateScheduleEvent( + index: 0)); } - twoGangBloc.toggleSelectedIndex(0); + twoGangBloc.add( + const ToggleSelectedEvent( + index: 0)); } else { - twoGangBloc.toggleSelectedIndex(1); + twoGangBloc.add( + const ToggleSelectedEvent( + index: 1)); } }, indicatorColor: @@ -243,12 +252,20 @@ class TimerScheduleScreen extends StatelessWidget { children: [ Expanded( child: ScheduleListView( - listSchedule: twoGangBloc.listSchedule, // Pass the schedule list here - onDismissed:(scheduleId) { - twoGangBloc .listSchedule - .removeWhere( (schedule) => schedule .scheduleId == scheduleId); + listSchedule: twoGangBloc + .listSchedule, // Pass the schedule list here + onDismissed: + (scheduleId) { + twoGangBloc + .listSchedule + .removeWhere( + (schedule) => + schedule + .scheduleId == + scheduleId); twoGangBloc.add( - DeleteScheduleEvent( id: scheduleId)); + DeleteScheduleEvent( + id: scheduleId)); }, onToggleSchedule: (scheduleId, diff --git a/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart b/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart index 5787f9c..de027a9 100644 --- a/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart +++ b/lib/features/devices/view/widgets/water_heater/wh_timer_schedule_screen.dart @@ -86,7 +86,10 @@ class WHTimerScheduleScreen extends StatelessWidget { : waterHeaterBloc.selectedTabIndex == 1 ? IconButton( onPressed: () { - waterHeaterBloc.toggleCreateSchedule(); + // waterHeaterBloc.toggleCreateSchedule(); + waterHeaterBloc.add( + const ToggleCreateScheduleEvent( + index: 1)); }, icon: const Icon(Icons.add), ) @@ -129,27 +132,45 @@ class WHTimerScheduleScreen extends StatelessWidget { if (value == 0) { if (waterHeaterBloc.createSchedule == true) { - waterHeaterBloc - .toggleCreateSchedule(); + // waterHeaterBloc + // .toggleCreateSchedule(); + waterHeaterBloc.add( + const ToggleCreateScheduleEvent( + index: 1)); } - waterHeaterBloc - .toggleSelectedIndex(value); + waterHeaterBloc.add( + ToggleSelectedEvent( + index: value)); + // waterHeaterBloc + // .toggleSelectedIndex(value); } else if (value == 2) { if (waterHeaterBloc.createCirculate == true) { - waterHeaterBloc - .toggleCreateCirculate(); + waterHeaterBloc.add( + ToggleCreateCirculateEvent( + index: value)); + // waterHeaterBloc + // .toggleCreateCirculate(); } - waterHeaterBloc - .toggleSelectedIndex(value); + waterHeaterBloc.add( + ToggleSelectedEvent( + index: value)); + // waterHeaterBloc + // .toggleSelectedIndex(value); } else { if (waterHeaterBloc.createSchedule == true) { - waterHeaterBloc - .toggleCreateSchedule(); + waterHeaterBloc.add( + ToggleSelectedEvent( + index: value)); + // waterHeaterBloc + // .toggleCreateSchedule(); } - waterHeaterBloc - .toggleSelectedIndex(value); + waterHeaterBloc.add( + ToggleSelectedEvent( + index: value)); + // waterHeaterBloc + // .toggleSelectedIndex(value); } }, indicatorColor: Colors.white,