mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
fix: handle nullable duration for breaks and correctly update breaks
This commit is contained in:
parent
5b98ae487b
commit
020d7a71f8
2 changed files with 16 additions and 4 deletions
|
@ -33,6 +33,14 @@ class BreakViewModel {
|
|||
/// [endTime]
|
||||
final Duration? duration;
|
||||
|
||||
/// Get the duration in minutes
|
||||
/// If the duration is null, return the difference between the start and end
|
||||
/// time in minutes
|
||||
int get durationInMinutes =>
|
||||
duration?.inMinutes ??
|
||||
((endTime!.hour * 60 + endTime!.minute) -
|
||||
(startTime!.hour * 60 + startTime!.minute));
|
||||
|
||||
/// Returns true if the break is valid
|
||||
/// The start is before the end and the duration is equal or lower than the
|
||||
/// difference between the start and end
|
||||
|
|
|
@ -56,8 +56,9 @@ class PauseSelection extends StatelessWidget {
|
|||
Future<void> onEditBreak(BreakViewModel availabilityBreak) async {
|
||||
var updatedBreak = await openBreakDialog(availabilityBreak);
|
||||
if (updatedBreak == null) return;
|
||||
|
||||
// remove the old break and add the updated one
|
||||
var updatedBreaks = [...breaks, updatedBreak];
|
||||
updatedBreaks.remove(availabilityBreak);
|
||||
onBreaksChanged(updatedBreaks);
|
||||
}
|
||||
|
||||
|
@ -145,6 +146,8 @@ class BreakDisplay extends StatelessWidget {
|
|||
breakModel.endTime!,
|
||||
);
|
||||
|
||||
var breakDuration = breakModel.durationInMinutes;
|
||||
|
||||
return InkWell(
|
||||
onTap: onClick,
|
||||
child: Container(
|
||||
|
@ -157,7 +160,7 @@ class BreakDisplay extends StatelessWidget {
|
|||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"${breakModel.duration!.inMinutes} "
|
||||
"$breakDuration "
|
||||
"${translations.timeMinutes} | "
|
||||
"$starTime - "
|
||||
"$endTime",
|
||||
|
@ -267,10 +270,11 @@ class _AvailabilityBreakSelectionDialogState
|
|||
? () {
|
||||
if (_breakViewModel.isValid) {
|
||||
Navigator.of(context).pop(_breakViewModel);
|
||||
}
|
||||
} else {
|
||||
debugPrint("Break is not valid");
|
||||
// TODO(freek): show error message
|
||||
}
|
||||
}
|
||||
: null;
|
||||
|
||||
var saveButton = options.primaryButtonBuilder(
|
||||
|
|
Loading…
Reference in a new issue