Join the space through the invitation code_ac countdown

This commit is contained in:
mohammad
2025-01-09 15:35:04 +03:00
parent 7a22bb4bc8
commit cc9ddffa44
4 changed files with 19 additions and 35 deletions

View File

@ -131,7 +131,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
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<AcsEvent, AcsState> {
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<AcsEvent, AcsState> {
emit(AcsFailedState(errorMessage: e.toString()));
return;
}
if (seconds > 0) {
if (event.duration > 0) {
_onStartTimer(seconds);
} else {
_timer?.cancel();
@ -479,26 +477,13 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
}
void _onStartTimer(int seconds) {
_timer?.cancel(); // Cancel any existing timer
_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());
}
}
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
add(TickTimer(remainingTime: seconds - timer.tick));
});
}
void _onTickTimer(TickTimer event, Emitter<AcsState> emit) {
if (!isClosed) {
// Check if the Bloc is still active
if (event.remainingTime > 0) {
emit(TimerRunInProgress(event.remainingTime));
} else {
@ -506,7 +491,6 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
emit(TimerRunComplete());
}
}
}
void _onClose(OnClose event, Emitter<AcsState> emit) {
_timer?.cancel(); // Cancel the timer

View File

@ -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:

View File

@ -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!');

View File

@ -91,7 +91,6 @@ class CreateUnitWidget extends StatelessWidget {
'Please enter the invitation code');
return;
}
//3Hsn4X
if (await HomeCubit.getInstance()
.activationCode(
textEditingController.text)) {