mirror of
https://github.com/Iconica-Development/flutter_availability.git
synced 2025-05-19 05:03:44 +02:00
feat: add custom timepicker option for overriding the default
This commit is contained in:
parent
239eb92609
commit
ff7ab2bc42
2 changed files with 17 additions and 4 deletions
|
@ -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,
|
||||
);
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue