mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 13:13: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]
|
/// [endTime]
|
||||||
final Duration? duration;
|
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
|
/// Returns true if the break is valid
|
||||||
/// The start is before the end and the duration is equal or lower than the
|
/// The start is before the end and the duration is equal or lower than the
|
||||||
/// difference between the start and end
|
/// difference between the start and end
|
||||||
|
|
|
@ -56,8 +56,9 @@ class PauseSelection extends StatelessWidget {
|
||||||
Future<void> onEditBreak(BreakViewModel availabilityBreak) async {
|
Future<void> onEditBreak(BreakViewModel availabilityBreak) async {
|
||||||
var updatedBreak = await openBreakDialog(availabilityBreak);
|
var updatedBreak = await openBreakDialog(availabilityBreak);
|
||||||
if (updatedBreak == null) return;
|
if (updatedBreak == null) return;
|
||||||
|
// remove the old break and add the updated one
|
||||||
var updatedBreaks = [...breaks, updatedBreak];
|
var updatedBreaks = [...breaks, updatedBreak];
|
||||||
|
updatedBreaks.remove(availabilityBreak);
|
||||||
onBreaksChanged(updatedBreaks);
|
onBreaksChanged(updatedBreaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +146,8 @@ class BreakDisplay extends StatelessWidget {
|
||||||
breakModel.endTime!,
|
breakModel.endTime!,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var breakDuration = breakModel.durationInMinutes;
|
||||||
|
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: onClick,
|
onTap: onClick,
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -157,7 +160,7 @@ class BreakDisplay extends StatelessWidget {
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"${breakModel.duration!.inMinutes} "
|
"$breakDuration "
|
||||||
"${translations.timeMinutes} | "
|
"${translations.timeMinutes} | "
|
||||||
"$starTime - "
|
"$starTime - "
|
||||||
"$endTime",
|
"$endTime",
|
||||||
|
@ -267,10 +270,11 @@ class _AvailabilityBreakSelectionDialogState
|
||||||
? () {
|
? () {
|
||||||
if (_breakViewModel.isValid) {
|
if (_breakViewModel.isValid) {
|
||||||
Navigator.of(context).pop(_breakViewModel);
|
Navigator.of(context).pop(_breakViewModel);
|
||||||
}
|
} else {
|
||||||
debugPrint("Break is not valid");
|
debugPrint("Break is not valid");
|
||||||
// TODO(freek): show error message
|
// TODO(freek): show error message
|
||||||
}
|
}
|
||||||
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
var saveButton = options.primaryButtonBuilder(
|
var saveButton = options.primaryButtonBuilder(
|
||||||
|
|
Loading…
Reference in a new issue