mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 10:06:16 +00:00
Join the space through the invitation code_ac countdown
This commit is contained in:
@ -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,32 +477,18 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
}
|
||||
|
||||
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<AcsState> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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!');
|
||||
|
@ -91,7 +91,6 @@ class CreateUnitWidget extends StatelessWidget {
|
||||
'Please enter the invitation code');
|
||||
return;
|
||||
}
|
||||
//3Hsn4X
|
||||
if (await HomeCubit.getInstance()
|
||||
.activationCode(
|
||||
textEditingController.text)) {
|
||||
|
Reference in New Issue
Block a user