From ff7ab2bc42c69824b41360c4f87eb345888a29fa Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Tue, 9 Jul 2024 17:31:02 +0200 Subject: [PATCH] feat: add custom timepicker option for overriding the default --- .../lib/src/config/availability_options.dart | 11 +++++++++++ .../lib/src/ui/widgets/input_fields.dart | 10 ++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/flutter_availability/lib/src/config/availability_options.dart b/packages/flutter_availability/lib/src/config/availability_options.dart index 5e6e2b7..edc01df 100644 --- a/packages/flutter_availability/lib/src/config/availability_options.dart +++ b/packages/flutter_availability/lib/src/config/availability_options.dart @@ -18,6 +18,7 @@ class AvailabilityOptions { this.spacing = const AvailabilitySpacing(), this.textStyles = const AvailabilityTextStyles(), this.colors = const AvailabilityColors(), + this.timePickerBuilder, AvailabilityDataInterface? dataInterface, }) : dataInterface = dataInterface ?? LocalAvailabilityDataInterface(); @@ -48,6 +49,10 @@ class AvailabilityOptions { /// The colors used in the userstory final AvailabilityColors colors; + + /// A way to provide your own time picker implementation or customize + /// the default time picker + final TimePickerBuilder? timePickerBuilder; } /// All configurable paddings and whitespaces withing the userstory @@ -137,3 +142,9 @@ typedef ButtonBuilder = Widget Function( FutureOr? Function()? onPressed, Widget child, ); + +/// Builder definition for providing a time picker implementation +typedef TimePickerBuilder = Future Function( + BuildContext context, + TimeOfDay? initialTime, +); diff --git a/packages/flutter_availability/lib/src/ui/widgets/input_fields.dart b/packages/flutter_availability/lib/src/ui/widgets/input_fields.dart index aefd7e3..7b8ba8b 100644 --- a/packages/flutter_availability/lib/src/ui/widgets/input_fields.dart +++ b/packages/flutter_availability/lib/src/ui/widgets/input_fields.dart @@ -24,10 +24,12 @@ class TimeInputField extends StatelessWidget { var translations = options.translations; Future onFieldtap() async { - var time = await showTimePicker( - context: context, - initialTime: TimeOfDay.fromDateTime(initialValue ?? DateTime.now()), - ); + var initialTime = TimeOfDay.fromDateTime(initialValue ?? DateTime.now()); + var time = await (options.timePickerBuilder?.call(context, initialTime) ?? + showTimePicker( + context: context, + initialTime: TimeOfDay.fromDateTime(initialValue ?? DateTime.now()), + )); if (time != null) { onTimeChanged( DateTime(