mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +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) {
|
if (allAcsPage) {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
for (AcStatusModel ac in deviceStatusList) {
|
for (AcStatusModel ac in deviceStatusList) {
|
||||||
if (ac.uuid == event.productId) {
|
if (ac.uuid == event.deviceId) {
|
||||||
ac.acSwitch = acSwitchValue;
|
ac.acSwitch = acSwitchValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,8 +438,6 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
|
|
||||||
if (response['success'] ?? false) {
|
if (response['success'] ?? false) {
|
||||||
deviceStatus.countdown1 = seconds;
|
deviceStatus.countdown1 = seconds;
|
||||||
|
|
||||||
emit(UpdateTimerState(seconds: deviceStatus.countdown1));
|
|
||||||
} else {
|
} else {
|
||||||
emit(const AcsFailedState(errorMessage: 'Something went wrong'));
|
emit(const AcsFailedState(errorMessage: 'Something went wrong'));
|
||||||
return;
|
return;
|
||||||
@ -448,7 +446,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
emit(AcsFailedState(errorMessage: e.toString()));
|
emit(AcsFailedState(errorMessage: e.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (seconds > 0) {
|
if (event.duration > 0) {
|
||||||
_onStartTimer(seconds);
|
_onStartTimer(seconds);
|
||||||
} else {
|
} else {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
@ -479,32 +477,18 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onStartTimer(int seconds) {
|
void _onStartTimer(int seconds) {
|
||||||
_timer?.cancel(); // Cancel any existing timer
|
_timer?.cancel();
|
||||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
final remainingTime = seconds - timer.tick;
|
add(TickTimer(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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onTickTimer(TickTimer event, Emitter<AcsState> emit) {
|
void _onTickTimer(TickTimer event, Emitter<AcsState> emit) {
|
||||||
if (!isClosed) {
|
if (event.remainingTime > 0) {
|
||||||
// Check if the Bloc is still active
|
emit(TimerRunInProgress(event.remainingTime));
|
||||||
if (event.remainingTime > 0) {
|
} else {
|
||||||
emit(TimerRunInProgress(event.remainingTime));
|
_timer?.cancel();
|
||||||
} else {
|
emit(TimerRunComplete());
|
||||||
_timer?.cancel();
|
|
||||||
emit(TimerRunComplete());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +109,14 @@ class AcTimerPage extends StatelessWidget {
|
|||||||
(value * 10).toInt();
|
(value * 10).toInt();
|
||||||
if (selectedValue == 5) {
|
if (selectedValue == 5) {
|
||||||
duration = const Duration(
|
duration = const Duration(
|
||||||
minutes:
|
minutes: 30);
|
||||||
30); // 0.5 translates to 30 minutes
|
|
||||||
countNum =
|
countNum =
|
||||||
duration.inSeconds;
|
duration.inSeconds;
|
||||||
} else {
|
} else {
|
||||||
duration = Duration(
|
duration = Duration(
|
||||||
minutes: selectedValue *
|
minutes:
|
||||||
6); // Each step represents 6 minutes
|
selectedValue *
|
||||||
|
6);
|
||||||
countNum =
|
countNum =
|
||||||
duration.inSeconds;
|
duration.inSeconds;
|
||||||
}
|
}
|
||||||
@ -133,11 +133,9 @@ class AcTimerPage extends StatelessWidget {
|
|||||||
if (countNum > 0) {
|
if (countNum > 0) {
|
||||||
oneGangBloc.add(SetCounterValue(
|
oneGangBloc.add(SetCounterValue(
|
||||||
seconds: countNum,
|
seconds: countNum,
|
||||||
deviceCode:
|
deviceCode:'countdown_time',
|
||||||
'countdown_time',
|
|
||||||
duration: selectedValue));
|
duration: selectedValue));
|
||||||
} else if (duration !=
|
} else if (duration != Duration.zero) {
|
||||||
Duration.zero) {
|
|
||||||
oneGangBloc.add(SetCounterValue(
|
oneGangBloc.add(SetCounterValue(
|
||||||
seconds: 0,
|
seconds: 0,
|
||||||
deviceCode:
|
deviceCode:
|
||||||
|
@ -58,8 +58,11 @@ class JoinHomeView extends StatelessWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await HomeCubit.getInstance()
|
if (await HomeCubit.getInstance()
|
||||||
.joinAUnit(textEditingController.text)) {
|
.activationCode(textEditingController.text)) {
|
||||||
|
await HomeCubit.getInstance().fetchUnitsByUserId();
|
||||||
|
|
||||||
CustomSnackBar.displaySnackBar('Done successfully');
|
CustomSnackBar.displaySnackBar('Done successfully');
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
} else {
|
} else {
|
||||||
CustomSnackBar.displaySnackBar('Wrong code!');
|
CustomSnackBar.displaySnackBar('Wrong code!');
|
||||||
|
@ -91,7 +91,6 @@ class CreateUnitWidget extends StatelessWidget {
|
|||||||
'Please enter the invitation code');
|
'Please enter the invitation code');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//3Hsn4X
|
|
||||||
if (await HomeCubit.getInstance()
|
if (await HomeCubit.getInstance()
|
||||||
.activationCode(
|
.activationCode(
|
||||||
textEditingController.text)) {
|
textEditingController.text)) {
|
||||||
|
Reference in New Issue
Block a user