From 17fc6ad9f6f1699cc2dc2c0e10bb6da684e8ffe7 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Wed, 24 Jul 2024 13:38:41 +0200 Subject: [PATCH] fix: clear start and end before applying a template to an availability selection The start and end might already be set before selecting a template, it should always be cleared and if the template is uniform it can update the start and endtime to the correct value --- .../view_models/availability_view_model.dart | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/flutter_availability/lib/src/ui/view_models/availability_view_model.dart b/packages/flutter_availability/lib/src/ui/view_models/availability_view_model.dart index 20fbedc..92b13b0 100644 --- a/packages/flutter_availability/lib/src/ui/view_models/availability_view_model.dart +++ b/packages/flutter_availability/lib/src/ui/view_models/availability_view_model.dart @@ -150,7 +150,7 @@ class AvailabilityViewModel { } } - return copyWith( + return clearTimeAndBreak().copyWith( templates: [template], breaks: breaks, conflictingPauses: conflictingPauses, @@ -161,12 +161,27 @@ class AvailabilityViewModel { ); } - /// + /// Removes the templates from the availability AvailabilityViewModel removeTemplates() => copyWith( templates: [], templateSelected: false, ); + /// Removes the time and breaks from the availability + AvailabilityViewModel clearTimeAndBreak() => AvailabilityViewModel( + selectedRange: selectedRange, + templates: templates, + ids: ids, + userId: userId, + startTime: null, + endTime: null, + breaks: [], + clearAvailability: clearAvailability, + conflictingPauses: conflictingPauses, + conflictingTime: conflictingTime, + templateSelected: templateSelected, + ); + /// create a AvailabilityModel from the current AvailabilityViewModel AvailabilityModel toModel() { var startDate = DateTime(