mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
feat: add button for clearing selected availabilities on availability overview
This commit is contained in:
parent
e3474e779b
commit
5bfac2f4e3
3 changed files with 66 additions and 15 deletions
|
@ -18,6 +18,9 @@ class AvailabilityTranslations {
|
|||
required this.availabilityWithoutTemplateLabel,
|
||||
required this.overviewScreenTitle,
|
||||
required this.createTemplateButton,
|
||||
required this.clearAvailabilityButton,
|
||||
required this.clearAvailabilityConfirmTitle,
|
||||
required this.clearAvailabilityConfirmDescription,
|
||||
required this.unavailableForDay,
|
||||
required this.unavailableForMultipleDays,
|
||||
required this.availabilityAddTemplateTitle,
|
||||
|
@ -63,6 +66,10 @@ class AvailabilityTranslations {
|
|||
this.templateSelectionLabel = "Selected day(s)",
|
||||
this.availabilityWithoutTemplateLabel = "Availabilty without template",
|
||||
this.createTemplateButton = "Create a new template",
|
||||
this.clearAvailabilityButton = "Not available on these days",
|
||||
this.clearAvailabilityConfirmTitle = "Are you sure you want to clear?",
|
||||
this.clearAvailabilityConfirmDescription =
|
||||
"This will remove all availabilities for the selected days",
|
||||
this.unavailableForDay = "I am not available this day",
|
||||
this.unavailableForMultipleDays = "I am not available these days",
|
||||
this.availabilityAddTemplateTitle = "Add template to availability",
|
||||
|
@ -123,6 +130,16 @@ class AvailabilityTranslations {
|
|||
/// The label on the button to go to the template screen
|
||||
final String createTemplateButton;
|
||||
|
||||
/// The text shown on the button to clear the selected range on the
|
||||
/// overview page
|
||||
final String clearAvailabilityButton;
|
||||
|
||||
/// The title for the confirmation dialog when clearing the availability
|
||||
final String clearAvailabilityConfirmTitle;
|
||||
|
||||
/// The description for the confirmation dialog when clearing the availability
|
||||
final String clearAvailabilityConfirmDescription;
|
||||
|
||||
/// The text shown to clear the availability for a day
|
||||
final String unavailableForDay;
|
||||
|
||||
|
|
|
@ -51,6 +51,20 @@ class _AvailabilityOverviewState extends State<AvailabilityOverview> {
|
|||
|
||||
var availabilitySnapshot = useStream(availabilityStream);
|
||||
|
||||
var selectedAvailabilities = _selectedRange != null
|
||||
? availabilitySnapshot.data
|
||||
?.where(
|
||||
(a) =>
|
||||
!a.availabilityModel.startDate
|
||||
.isBefore(_selectedRange!.start) &&
|
||||
!a.availabilityModel.endDate.isAfter(_selectedRange!.end),
|
||||
)
|
||||
.toList() ??
|
||||
<AvailabilityWithTemplate>[]
|
||||
: <AvailabilityWithTemplate>[];
|
||||
|
||||
var availabilitiesAreSelected = selectedAvailabilities.isNotEmpty;
|
||||
|
||||
var title = Center(
|
||||
child: Text(
|
||||
translations.overviewScreenTitle,
|
||||
|
@ -82,26 +96,36 @@ class _AvailabilityOverviewState extends State<AvailabilityOverview> {
|
|||
var onButtonPress = _selectedRange == null
|
||||
? null
|
||||
: () {
|
||||
var availabilitesWithinSelectedRange = availabilitySnapshot.data
|
||||
?.where(
|
||||
(a) =>
|
||||
a.availabilityModel.startDate
|
||||
.isAfter(_selectedRange!.start) &&
|
||||
a.availabilityModel.endDate
|
||||
.isBefore(_selectedRange!.end),
|
||||
)
|
||||
.toList() ??
|
||||
<AvailabilityWithTemplate>[];
|
||||
|
||||
widget.onEditDateRange(
|
||||
_selectedRange!,
|
||||
availabilitesWithinSelectedRange,
|
||||
selectedAvailabilities,
|
||||
);
|
||||
setState(() {
|
||||
_selectedRange = null;
|
||||
});
|
||||
};
|
||||
|
||||
Future<void> onClearButtonClicked() async {
|
||||
var confirmed = await options.confirmationDialogBuilder(
|
||||
context,
|
||||
title: translations.clearAvailabilityConfirmTitle,
|
||||
description: translations.clearAvailabilityConfirmDescription,
|
||||
);
|
||||
if (confirmed ?? false) {
|
||||
await service
|
||||
.clearAvailabilities(selectedAvailabilities.getAvailabilities());
|
||||
setState(() {
|
||||
_selectedRange = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var clearSelectedButton = options.textButtonBuilder(
|
||||
context,
|
||||
onClearButtonClicked,
|
||||
Text(translations.clearAvailabilityButton),
|
||||
);
|
||||
|
||||
var startEditButton = options.primaryButtonBuilder(
|
||||
context,
|
||||
onButtonPress,
|
||||
|
@ -135,7 +159,15 @@ class _AvailabilityOverviewState extends State<AvailabilityOverview> {
|
|||
),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: startEditButton,
|
||||
child: Column(
|
||||
children: [
|
||||
startEditButton,
|
||||
if (availabilitiesAreSelected) ...[
|
||||
const SizedBox(height: 8),
|
||||
clearSelectedButton,
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -105,9 +105,11 @@ class _AvailabilityDayTemplateEditState
|
|||
var timeSection = TemplateTimeSelection(
|
||||
key: ValueKey(_template.templateData),
|
||||
startTime: TimeOfDay.fromDateTime(
|
||||
(_template.templateData as DayTemplateData).startTime,),
|
||||
(_template.templateData as DayTemplateData).startTime,
|
||||
),
|
||||
endTime: TimeOfDay.fromDateTime(
|
||||
(_template.templateData as DayTemplateData).endTime,),
|
||||
(_template.templateData as DayTemplateData).endTime,
|
||||
),
|
||||
onStartChanged: (start) {
|
||||
var startTime = (_template.templateData as DayTemplateData).startTime;
|
||||
var updatedStartTime = DateTime(
|
||||
|
|
Loading…
Reference in a new issue