mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +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(
|
emit(currentState.copyWith(
|
||||||
scheduleMode: event.scheduleMode,
|
scheduleMode: event.scheduleMode,
|
||||||
countdownRemaining: Duration.zero,
|
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) {
|
if (state is ScheduleLoaded) {
|
||||||
final currentState = state as ScheduleLoaded;
|
final currentState = state as ScheduleLoaded;
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
|
countdownSeconds: event.seconds,
|
||||||
countdownHours: event.hours,
|
countdownHours: event.hours,
|
||||||
countdownMinutes: event.minutes,
|
countdownMinutes: event.minutes,
|
||||||
inchingHours: 0,
|
inchingHours: 0,
|
||||||
@ -113,6 +120,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
inchingHours: event.hours,
|
inchingHours: event.hours,
|
||||||
inchingMinutes: event.minutes,
|
inchingMinutes: event.minutes,
|
||||||
countdownRemaining: Duration.zero,
|
countdownRemaining: Duration.zero,
|
||||||
|
inchingSeconds: 0, // Add this
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,6 +432,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
countdownMinutes: countdownDuration.inMinutes % 60,
|
countdownMinutes: countdownDuration.inMinutes % 60,
|
||||||
countdownRemaining: countdownDuration,
|
countdownRemaining: countdownDuration,
|
||||||
isCountdownActive: true,
|
isCountdownActive: true,
|
||||||
|
countdownSeconds: countdownDuration.inSeconds,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -437,6 +446,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
countdownMinutes: 0,
|
countdownMinutes: 0,
|
||||||
countdownRemaining: Duration.zero,
|
countdownRemaining: Duration.zero,
|
||||||
isCountdownActive: false,
|
isCountdownActive: false,
|
||||||
|
countdownSeconds: 0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -448,6 +458,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
inchingMinutes: inchingDuration.inMinutes % 60,
|
inchingMinutes: inchingDuration.inMinutes % 60,
|
||||||
isInchingActive: true,
|
isInchingActive: true,
|
||||||
countdownRemaining: inchingDuration,
|
countdownRemaining: inchingDuration,
|
||||||
|
countdownSeconds: inchingDuration.inSeconds,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -574,8 +585,7 @@ class ScheduleBloc extends Bloc<ScheduleEvent, ScheduleState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String extractTime(String isoDateTime) {
|
String extractTime(String isoDateTime) {
|
||||||
// Example input: "2025-06-19T15:45:00.000"
|
return isoDateTime.split('T')[1].split('.')[0];
|
||||||
return isoDateTime.split('T')[1].split('.')[0]; // gives "15:45:00"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
int? getTimeStampWithoutSeconds(DateTime? dateTime) {
|
||||||
|
@ -146,14 +146,16 @@ class UpdateScheduleModeEvent extends ScheduleEvent {
|
|||||||
class UpdateCountdownTimeEvent extends ScheduleEvent {
|
class UpdateCountdownTimeEvent extends ScheduleEvent {
|
||||||
final int hours;
|
final int hours;
|
||||||
final int minutes;
|
final int minutes;
|
||||||
|
final int seconds;
|
||||||
|
|
||||||
const UpdateCountdownTimeEvent({
|
const UpdateCountdownTimeEvent({
|
||||||
required this.hours,
|
required this.hours,
|
||||||
required this.minutes,
|
required this.minutes,
|
||||||
|
required this.seconds,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [hours, minutes];
|
List<Object> get props => [hours, minutes, seconds];
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateInchingTimeEvent extends ScheduleEvent {
|
class UpdateInchingTimeEvent extends ScheduleEvent {
|
||||||
|
@ -26,11 +26,15 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
final bool isCountdownActive;
|
final bool isCountdownActive;
|
||||||
final int inchingHours;
|
final int inchingHours;
|
||||||
final int inchingMinutes;
|
final int inchingMinutes;
|
||||||
|
final int inchingSeconds;
|
||||||
final bool isInchingActive;
|
final bool isInchingActive;
|
||||||
final ScheduleModes scheduleMode;
|
final ScheduleModes scheduleMode;
|
||||||
final Duration? countdownRemaining;
|
final Duration? countdownRemaining;
|
||||||
|
final int? countdownSeconds;
|
||||||
|
|
||||||
const ScheduleLoaded({
|
const ScheduleLoaded({
|
||||||
|
this.countdownSeconds = 0,
|
||||||
|
this.inchingSeconds = 0,
|
||||||
required this.schedules,
|
required this.schedules,
|
||||||
this.selectedTime,
|
this.selectedTime,
|
||||||
required this.selectedDays,
|
required this.selectedDays,
|
||||||
@ -61,6 +65,9 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
bool? isInchingActive,
|
bool? isInchingActive,
|
||||||
ScheduleModes? scheduleMode,
|
ScheduleModes? scheduleMode,
|
||||||
Duration? countdownRemaining,
|
Duration? countdownRemaining,
|
||||||
|
String? deviceId,
|
||||||
|
int? countdownSeconds,
|
||||||
|
int? inchingSeconds,
|
||||||
}) {
|
}) {
|
||||||
return ScheduleLoaded(
|
return ScheduleLoaded(
|
||||||
schedules: schedules ?? this.schedules,
|
schedules: schedules ?? this.schedules,
|
||||||
@ -68,7 +75,7 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
selectedDays: selectedDays ?? this.selectedDays,
|
selectedDays: selectedDays ?? this.selectedDays,
|
||||||
functionOn: functionOn ?? this.functionOn,
|
functionOn: functionOn ?? this.functionOn,
|
||||||
isEditing: isEditing ?? this.isEditing,
|
isEditing: isEditing ?? this.isEditing,
|
||||||
deviceId: deviceId,
|
deviceId: deviceId ?? this.deviceId,
|
||||||
countdownHours: countdownHours ?? this.countdownHours,
|
countdownHours: countdownHours ?? this.countdownHours,
|
||||||
countdownMinutes: countdownMinutes ?? this.countdownMinutes,
|
countdownMinutes: countdownMinutes ?? this.countdownMinutes,
|
||||||
isCountdownActive: isCountdownActive ?? this.isCountdownActive,
|
isCountdownActive: isCountdownActive ?? this.isCountdownActive,
|
||||||
@ -77,6 +84,8 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
isInchingActive: isInchingActive ?? this.isInchingActive,
|
isInchingActive: isInchingActive ?? this.isInchingActive,
|
||||||
scheduleMode: scheduleMode ?? this.scheduleMode,
|
scheduleMode: scheduleMode ?? this.scheduleMode,
|
||||||
countdownRemaining: countdownRemaining ?? this.countdownRemaining,
|
countdownRemaining: countdownRemaining ?? this.countdownRemaining,
|
||||||
|
countdownSeconds: countdownSeconds ?? this.countdownSeconds,
|
||||||
|
inchingSeconds: inchingSeconds ?? this.inchingSeconds,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +105,8 @@ class ScheduleLoaded extends ScheduleState {
|
|||||||
isInchingActive,
|
isInchingActive,
|
||||||
scheduleMode,
|
scheduleMode,
|
||||||
countdownRemaining,
|
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';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
class CountdownInchingView extends StatefulWidget {
|
class CountdownInchingView extends StatefulWidget {
|
||||||
const CountdownInchingView({super.key});
|
final String deviceId;
|
||||||
|
const CountdownInchingView({super.key, required this.deviceId});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<CountdownInchingView> createState() => _CountdownInchingViewState();
|
State<CountdownInchingView> createState() => _CountdownInchingViewState();
|
||||||
@ -15,25 +16,30 @@ class CountdownInchingView extends StatefulWidget {
|
|||||||
class _CountdownInchingViewState extends State<CountdownInchingView> {
|
class _CountdownInchingViewState extends State<CountdownInchingView> {
|
||||||
late FixedExtentScrollController _hoursController;
|
late FixedExtentScrollController _hoursController;
|
||||||
late FixedExtentScrollController _minutesController;
|
late FixedExtentScrollController _minutesController;
|
||||||
|
late FixedExtentScrollController _secondsController;
|
||||||
|
|
||||||
int _lastHours = -1;
|
int _lastHours = -1;
|
||||||
int _lastMinutes = -1;
|
int _lastMinutes = -1;
|
||||||
|
int _lastSeconds = -1;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_hoursController = FixedExtentScrollController();
|
_hoursController = FixedExtentScrollController();
|
||||||
_minutesController = FixedExtentScrollController();
|
_minutesController = FixedExtentScrollController();
|
||||||
|
_secondsController = FixedExtentScrollController();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_hoursController.dispose();
|
_hoursController.dispose();
|
||||||
_minutesController.dispose();
|
_minutesController.dispose();
|
||||||
|
_secondsController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateControllers(int displayHours, int displayMinutes) {
|
void _updateControllers(
|
||||||
|
int displayHours, int displayMinutes, int displaySeconds) {
|
||||||
if (_lastHours != displayHours) {
|
if (_lastHours != displayHours) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (_hoursController.hasClients) {
|
if (_hoursController.hasClients) {
|
||||||
@ -50,6 +56,15 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
|||||||
});
|
});
|
||||||
_lastMinutes = displayMinutes;
|
_lastMinutes = displayMinutes;
|
||||||
}
|
}
|
||||||
|
// Update seconds controller
|
||||||
|
if (_lastSeconds != displaySeconds) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (_secondsController.hasClients) {
|
||||||
|
_secondsController.jumpToItem(displaySeconds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_lastSeconds = displaySeconds;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -57,7 +72,6 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
|||||||
return BlocBuilder<ScheduleBloc, ScheduleState>(
|
return BlocBuilder<ScheduleBloc, ScheduleState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is! ScheduleLoaded) return const SizedBox.shrink();
|
if (state is! ScheduleLoaded) return const SizedBox.shrink();
|
||||||
|
|
||||||
final isCountDown = state.scheduleMode == ScheduleModes.countdown;
|
final isCountDown = state.scheduleMode == ScheduleModes.countdown;
|
||||||
final isActive =
|
final isActive =
|
||||||
isCountDown ? state.isCountdownActive : state.isInchingActive;
|
isCountDown ? state.isCountdownActive : state.isInchingActive;
|
||||||
@ -67,8 +81,21 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
|||||||
final displayMinutes = isActive && state.countdownRemaining != null
|
final displayMinutes = isActive && state.countdownRemaining != null
|
||||||
? state.countdownRemaining!.inMinutes.remainder(60)
|
? state.countdownRemaining!.inMinutes.remainder(60)
|
||||||
: (isCountDown ? state.countdownMinutes : state.inchingMinutes);
|
: (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(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -100,7 +127,10 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
|||||||
(value) {
|
(value) {
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
context.read<ScheduleBloc>().add(UpdateCountdownTimeEvent(
|
context.read<ScheduleBloc>().add(UpdateCountdownTimeEvent(
|
||||||
hours: value, minutes: displayMinutes));
|
hours: value,
|
||||||
|
minutes: displayMinutes,
|
||||||
|
seconds: displaySeconds,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isActive: isActive,
|
isActive: isActive,
|
||||||
@ -115,7 +145,31 @@ class _CountdownInchingViewState extends State<CountdownInchingView> {
|
|||||||
(value) {
|
(value) {
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
context.read<ScheduleBloc>().add(UpdateCountdownTimeEvent(
|
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,
|
isActive: isActive,
|
||||||
|
@ -74,7 +74,9 @@ class BuildScheduleView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
if (state.scheduleMode == ScheduleModes.countdown ||
|
if (state.scheduleMode == ScheduleModes.countdown ||
|
||||||
state.scheduleMode == ScheduleModes.inching)
|
state.scheduleMode == ScheduleModes.inching)
|
||||||
const CountdownInchingView(),
|
CountdownInchingView(
|
||||||
|
deviceId: deviceUuid,
|
||||||
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
if (state.scheduleMode == ScheduleModes.countdown)
|
if (state.scheduleMode == ScheduleModes.countdown)
|
||||||
CountdownModeButtons(
|
CountdownModeButtons(
|
||||||
|
Reference in New Issue
Block a user