feat: add custom timepicker option for overriding the default

This commit is contained in:
Freek van de Ven 2024-07-09 17:31:02 +02:00 committed by Bart Ribbers
parent 239eb92609
commit ff7ab2bc42
2 changed files with 17 additions and 4 deletions

View file

@ -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<void>? Function()? onPressed,
Widget child,
);
/// Builder definition for providing a time picker implementation
typedef TimePickerBuilder = Future<TimeOfDay?> Function(
BuildContext context,
TimeOfDay? initialTime,
);

View file

@ -24,10 +24,12 @@ class TimeInputField extends StatelessWidget {
var translations = options.translations;
Future<void> 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(