From cc9ddffa443632e6c16368c6df5c8b921c588430 Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 9 Jan 2025 15:35:04 +0300 Subject: [PATCH] Join the space through the invitation code_ac countdown --- .../devices/bloc/acs_bloc/acs_bloc.dart | 34 +++++-------------- .../view/widgets/ACs/ac_timer_page.dart | 14 ++++---- .../widgets/join_home/join_home_view.dart | 5 ++- lib/features/shared_widgets/create_unit.dart | 1 - 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart index a101b80..33dd1dd 100644 --- a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart +++ b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart @@ -131,7 +131,7 @@ class ACsBloc extends Bloc { if (allAcsPage) { emit(AcsLoadingState()); for (AcStatusModel ac in deviceStatusList) { - if (ac.uuid == event.productId) { + if (ac.uuid == event.deviceId) { ac.acSwitch = acSwitchValue; } } @@ -438,8 +438,6 @@ class ACsBloc extends Bloc { if (response['success'] ?? false) { deviceStatus.countdown1 = seconds; - - emit(UpdateTimerState(seconds: deviceStatus.countdown1)); } else { emit(const AcsFailedState(errorMessage: 'Something went wrong')); return; @@ -448,7 +446,7 @@ class ACsBloc extends Bloc { emit(AcsFailedState(errorMessage: e.toString())); return; } - if (seconds > 0) { + if (event.duration > 0) { _onStartTimer(seconds); } else { _timer?.cancel(); @@ -479,32 +477,18 @@ class ACsBloc extends Bloc { } void _onStartTimer(int seconds) { - _timer?.cancel(); // Cancel any existing timer + _timer?.cancel(); _timer = Timer.periodic(const Duration(seconds: 1), (timer) { - final remainingTime = seconds - timer.tick; - if (remainingTime > 0) { - if (!isClosed) { - // Check if the Bloc is still active - add(TickTimer(remainingTime: remainingTime)); - } - } else { - _timer?.cancel(); - if (!isClosed) { - emit(TimerRunComplete()); - } - } + add(TickTimer(remainingTime: seconds - timer.tick)); }); } void _onTickTimer(TickTimer event, Emitter emit) { - if (!isClosed) { - // Check if the Bloc is still active - if (event.remainingTime > 0) { - emit(TimerRunInProgress(event.remainingTime)); - } else { - _timer?.cancel(); - emit(TimerRunComplete()); - } + if (event.remainingTime > 0) { + emit(TimerRunInProgress(event.remainingTime)); + } else { + _timer?.cancel(); + emit(TimerRunComplete()); } } diff --git a/lib/features/devices/view/widgets/ACs/ac_timer_page.dart b/lib/features/devices/view/widgets/ACs/ac_timer_page.dart index 6738094..e501a85 100644 --- a/lib/features/devices/view/widgets/ACs/ac_timer_page.dart +++ b/lib/features/devices/view/widgets/ACs/ac_timer_page.dart @@ -109,14 +109,14 @@ class AcTimerPage extends StatelessWidget { (value * 10).toInt(); if (selectedValue == 5) { duration = const Duration( - minutes: - 30); // 0.5 translates to 30 minutes + minutes: 30); countNum = duration.inSeconds; } else { duration = Duration( - minutes: selectedValue * - 6); // Each step represents 6 minutes + minutes: + selectedValue * + 6); countNum = duration.inSeconds; } @@ -133,11 +133,9 @@ class AcTimerPage extends StatelessWidget { if (countNum > 0) { oneGangBloc.add(SetCounterValue( seconds: countNum, - deviceCode: - 'countdown_time', + deviceCode:'countdown_time', duration: selectedValue)); - } else if (duration != - Duration.zero) { + } else if (duration != Duration.zero) { oneGangBloc.add(SetCounterValue( seconds: 0, deviceCode: diff --git a/lib/features/menu/view/widgets/join_home/join_home_view.dart b/lib/features/menu/view/widgets/join_home/join_home_view.dart index 5ce6c8f..0272cc4 100644 --- a/lib/features/menu/view/widgets/join_home/join_home_view.dart +++ b/lib/features/menu/view/widgets/join_home/join_home_view.dart @@ -58,8 +58,11 @@ class JoinHomeView extends StatelessWidget { return; } if (await HomeCubit.getInstance() - .joinAUnit(textEditingController.text)) { + .activationCode(textEditingController.text)) { + await HomeCubit.getInstance().fetchUnitsByUserId(); + CustomSnackBar.displaySnackBar('Done successfully'); + Navigator.of(context).pop(); } else { CustomSnackBar.displaySnackBar('Wrong code!'); diff --git a/lib/features/shared_widgets/create_unit.dart b/lib/features/shared_widgets/create_unit.dart index 88cd08b..05db4dd 100644 --- a/lib/features/shared_widgets/create_unit.dart +++ b/lib/features/shared_widgets/create_unit.dart @@ -91,7 +91,6 @@ class CreateUnitWidget extends StatelessWidget { 'Please enter the invitation code'); return; } - //3Hsn4X if (await HomeCubit.getInstance() .activationCode( textEditingController.text)) {