mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Add countdown seconds to schedule management (#291)
<!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Description <!--- Describe your changes in detail --> Add countdown seconds to schedule management ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [ ] ✨ New feature (non-breaking change which adds functionality) - [x] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore
This commit is contained in:
@ -83,6 +83,12 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
emit(currentState.copyWith(
|
||||
scheduleMode: event.scheduleMode,
|
||||
countdownRemaining: Duration.zero,
|
||||
countdownHours: 0,
|
||||
countdownMinutes: 0,
|
||||
inchingHours: 0,
|
||||
inchingMinutes: 0,
|
||||
isCountdownActive: false,
|
||||
isInchingActive: false,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -94,6 +100,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
if (state is ScheduleLoaded) {
|
||||
final currentState = state as ScheduleLoaded;
|
||||
emit(currentState.copyWith(
|
||||
countdownSeconds: event.seconds,
|
||||
countdownHours: event.hours,
|
||||
countdownMinutes: event.minutes,
|
||||
inchingHours: 0,
|
||||
@ -113,6 +120,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
inchingHours: event.hours,
|
||||
inchingMinutes: event.minutes,
|
||||
countdownRemaining: Duration.zero,
|
||||
inchingSeconds: 0, // Add this
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -424,6 +432,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
countdownMinutes: countdownDuration.inMinutes % 60,
|
||||
countdownRemaining: countdownDuration,
|
||||
isCountdownActive: true,
|
||||
countdownSeconds: countdownDuration.inSeconds,
|
||||
),
|
||||
);
|
||||
|
||||
@ -437,6 +446,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
countdownMinutes: 0,
|
||||
countdownRemaining: Duration.zero,
|
||||
isCountdownActive: false,
|
||||
countdownSeconds: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -448,6 +458,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
inchingMinutes: inchingDuration.inMinutes % 60,
|
||||
isInchingActive: true,
|
||||
countdownRemaining: inchingDuration,
|
||||
countdownSeconds: inchingDuration.inSeconds,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -574,8 +585,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
||||
}
|
||||
|
||||
String extractTime(String isoDateTime) {
|
||||
// Example input: "2025-06-19T15:45:00.000"
|
||||
return isoDateTime.split('T')[1].split('.')[0]; // gives "15:45:00"
|
||||
return isoDateTime.split('T')[1].split('.')[0];
|
||||
}
|
||||
|
||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||
|
@ -146,14 +146,16 @@ class UpdateScheduleModeEvent extends ScheduleEvent {
|
||||
class UpdateCountdownTimeEvent extends ScheduleEvent {
|
||||
final int hours;
|
||||
final int minutes;
|
||||
final int seconds;
|
||||
|
||||
const UpdateCountdownTimeEvent({
|
||||
required this.hours,
|
||||
required this.minutes,
|
||||
required this.seconds,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [hours, minutes];
|
||||
List<Object> get props => [hours, minutes, seconds];
|
||||
}
|
||||
|
||||
class UpdateInchingTimeEvent extends ScheduleEvent {
|
||||
|
@ -26,11 +26,15 @@ class ScheduleLoaded extends ScheduleState {
|
||||
final bool isCountdownActive;
|
||||
final int inchingHours;
|
||||
final int inchingMinutes;
|
||||
final int inchingSeconds;
|
||||
final bool isInchingActive;
|
||||
final ScheduleModes scheduleMode;
|
||||
final Duration? countdownRemaining;
|
||||
final int? countdownSeconds;
|
||||
|
||||
const ScheduleLoaded({
|
||||
this.countdownSeconds = 0,
|
||||
this.inchingSeconds = 0,
|
||||
required this.schedules,
|
||||
this.selectedTime,
|
||||
required this.selectedDays,
|
||||
@ -61,6 +65,9 @@ class ScheduleLoaded extends ScheduleState {
|
||||
bool? isInchingActive,
|
||||
ScheduleModes? scheduleMode,
|
||||
Duration? countdownRemaining,
|
||||
String? deviceId,
|
||||
int? countdownSeconds,
|
||||
int? inchingSeconds,
|
||||
}) {
|
||||
return ScheduleLoaded(
|
||||
schedules: schedules ?? this.schedules,
|
||||
@ -68,7 +75,7 @@ class ScheduleLoaded extends ScheduleState {
|
||||
selectedDays: selectedDays ?? this.selectedDays,
|
||||
functionOn: functionOn ?? this.functionOn,
|
||||
isEditing: isEditing ?? this.isEditing,
|
||||
deviceId: deviceId,
|
||||
deviceId: deviceId ?? this.deviceId,
|
||||
countdownHours: countdownHours ?? this.countdownHours,
|
||||
countdownMinutes: countdownMinutes ?? this.countdownMinutes,
|
||||
isCountdownActive: isCountdownActive ?? this.isCountdownActive,
|
||||
@ -77,6 +84,8 @@ class ScheduleLoaded extends ScheduleState {
|
||||
isInchingActive: isInchingActive ?? this.isInchingActive,
|
||||
scheduleMode: scheduleMode ?? this.scheduleMode,
|
||||
countdownRemaining: countdownRemaining ?? this.countdownRemaining,
|
||||
countdownSeconds: countdownSeconds ?? this.countdownSeconds,
|
||||
inchingSeconds: inchingSeconds ?? this.inchingSeconds,
|
||||
);
|
||||
}
|
||||
|
||||
@ -96,6 +105,8 @@ class ScheduleLoaded extends ScheduleState {
|
||||
isInchingActive,
|
||||
scheduleMode,
|
||||
countdownRemaining,
|
||||
countdownSeconds,
|
||||
inchingSeconds,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,8 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class CountdownInchingView extends StatefulWidget {
|
||||
const CountdownInchingView({super.key});
|
||||
final String deviceId;
|
||||
const CountdownInchingView({super.key, required this.deviceId});
|
||||
|
||||
@override
|
||||
State<CountdownInchingView> createState() => _CountdownInchingViewState();
|
||||
@ -15,25 +16,30 @@ class CountdownInchingView extends StatefulWidget {
|
||||
class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||
late FixedExtentScrollController _hoursController;
|
||||
late FixedExtentScrollController _minutesController;
|
||||
late FixedExtentScrollController _secondsController;
|
||||
|
||||
int _lastHours = -1;
|
||||
int _lastMinutes = -1;
|
||||
int _lastSeconds = -1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_hoursController = FixedExtentScrollController();
|
||||
_minutesController = FixedExtentScrollController();
|
||||
_secondsController = FixedExtentScrollController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_hoursController.dispose();
|
||||
_minutesController.dispose();
|
||||
_secondsController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _updateControllers(int displayHours, int displayMinutes) {
|
||||
void _updateControllers(
|
||||
int displayHours, int displayMinutes, int displaySeconds) {
|
||||
if (_lastHours != displayHours) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_hoursController.hasClients) {
|
||||
@ -50,6 +56,15 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||
});
|
||||
_lastMinutes = displayMinutes;
|
||||
}
|
||||
// Update seconds controller
|
||||
if (_lastSeconds != displaySeconds) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_secondsController.hasClients) {
|
||||
_secondsController.jumpToItem(displaySeconds);
|
||||
}
|
||||
});
|
||||
_lastSeconds = displaySeconds;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@ -57,7 +72,6 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||
return BlocBuilder<ScheduleBloc, ScheduleState>(
|
||||
builder: (context, state) {
|
||||
if (state is! ScheduleLoaded) return const SizedBox.shrink();
|
||||
|
||||
final isCountDown = state.scheduleMode == ScheduleModes.countdown;
|
||||
final isActive =
|
||||
isCountDown ? state.isCountdownActive : state.isInchingActive;
|
||||
@ -67,8 +81,21 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||
final displayMinutes = isActive && state.countdownRemaining != null
|
||||
? state.countdownRemaining!.inMinutes.remainder(60)
|
||||
: (isCountDown ? state.countdownMinutes : state.inchingMinutes);
|
||||
final displaySeconds = isActive && state.countdownRemaining != null
|
||||
? state.countdownRemaining!.inSeconds.remainder(60)
|
||||
: (isCountDown ? state.countdownSeconds : state.inchingSeconds);
|
||||
|
||||
_updateControllers(displayHours, displayMinutes, displaySeconds!);
|
||||
|
||||
if (displayHours == 0 && displayMinutes == 0 && displaySeconds == 0) {
|
||||
context.read<ScheduleBloc>().add(
|
||||
StopScheduleEvent(
|
||||
mode: ScheduleModes.countdown,
|
||||
deviceId: widget.deviceId,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_updateControllers(displayHours, displayMinutes);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -100,7 +127,10 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||
(value) {
|
||||
if (!isActive) {
|
||||
context.read<ScheduleBloc>().add(UpdateCountdownTimeEvent(
|
||||
hours: value, minutes: displayMinutes));
|
||||
hours: value,
|
||||
minutes: displayMinutes,
|
||||
seconds: displaySeconds,
|
||||
));
|
||||
}
|
||||
},
|
||||
isActive: isActive,
|
||||
@ -115,11 +145,35 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||
(value) {
|
||||
if (!isActive) {
|
||||
context.read<ScheduleBloc>().add(UpdateCountdownTimeEvent(
|
||||
hours: displayHours, minutes: value));
|
||||
hours: displayHours,
|
||||
minutes: value,
|
||||
seconds: displaySeconds,
|
||||
));
|
||||
}
|
||||
},
|
||||
isActive: isActive,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
if (isActive)
|
||||
_buildPickerColumn(
|
||||
context,
|
||||
's',
|
||||
displaySeconds,
|
||||
60,
|
||||
_secondsController,
|
||||
(value) {
|
||||
if (!isActive) {
|
||||
context
|
||||
.read<ScheduleBloc>()
|
||||
.add(UpdateCountdownTimeEvent(
|
||||
hours: displayHours,
|
||||
minutes: displayMinutes,
|
||||
seconds: value,
|
||||
));
|
||||
}
|
||||
},
|
||||
isActive: isActive,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -74,7 +74,9 @@ class BuildScheduleView extends StatelessWidget {
|
||||
),
|
||||
if (state.scheduleMode == ScheduleModes.countdown ||
|
||||
state.scheduleMode == ScheduleModes.inching)
|
||||
const CountdownInchingView(),
|
||||
CountdownInchingView(
|
||||
deviceId: deviceUuid,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (state.scheduleMode == ScheduleModes.countdown)
|
||||
CountdownModeButtons(
|
||||
|
Reference in New Issue
Block a user