Added the ability to disable onTap of DateTimePicker

This commit is contained in:
Jacques 2023-10-26 16:12:37 +02:00
parent 8e4eb901a6
commit 1c221fadf9
4 changed files with 27 additions and 12 deletions

View file

@ -36,4 +36,8 @@
* Initial time optional on input from the user, defaulting to current time * Initial time optional on input from the user, defaulting to current time
## 2.3.0 ## 2.3.0
* The ability to set the enabled parameter of TextFormFields * The ability to set the enabled parameter of TextFormFields
## 2.4.0
* The ability to disable the onTap paramater of the DatePicker
* FlutterFormInputDateTime now also had the enabled parameter to provide to DateTimeInputField

View file

@ -34,6 +34,8 @@ class FlutterFormInputDateTime extends StatelessWidget {
this.validator, this.validator,
this.autovalidateMode = AutovalidateMode.disabled, this.autovalidateMode = AutovalidateMode.disabled,
this.timePickerEntryMode = TimePickerEntryMode.dial, this.timePickerEntryMode = TimePickerEntryMode.dial,
this.enabled = true,
this.onTapEnabled = true,
}) : super( }) : super(
key: key, key: key,
); );
@ -55,6 +57,8 @@ class FlutterFormInputDateTime extends StatelessWidget {
final void Function(String?)? onChanged; final void Function(String?)? onChanged;
final AutovalidateMode autovalidateMode; final AutovalidateMode autovalidateMode;
final TimePickerEntryMode timePickerEntryMode; final TimePickerEntryMode timePickerEntryMode;
final bool enabled;
final bool onTapEnabled;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -77,6 +81,8 @@ class FlutterFormInputDateTime extends StatelessWidget {
onSaved: (value) => onSaved?.call(value), onSaved: (value) => onSaved?.call(value),
showIcon: showIcon, showIcon: showIcon,
timePickerEntryMode: timePickerEntryMode, timePickerEntryMode: timePickerEntryMode,
enabled: enabled,
onTapEnabled: onTapEnabled,
); );
} }
} }

View file

@ -30,6 +30,7 @@ class DateTimeInputField extends StatefulWidget {
required this.timePickerEntryMode, required this.timePickerEntryMode,
required this.style, required this.style,
this.enabled = true, this.enabled = true,
this.onTapEnabled = true,
}) : super( }) : super(
key: key, key: key,
); );
@ -52,6 +53,7 @@ class DateTimeInputField extends StatefulWidget {
final void Function(String?)? onChanged; final void Function(String?)? onChanged;
final TimePickerEntryMode timePickerEntryMode; final TimePickerEntryMode timePickerEntryMode;
final bool enabled; final bool enabled;
final bool onTapEnabled;
@override @override
State<DateTimeInputField> createState() => _DateInputFieldState(); State<DateTimeInputField> createState() => _DateInputFieldState();
@ -174,16 +176,19 @@ class _DateInputFieldState extends State<DateTimeInputField> {
key: UniqueKey(), key: UniqueKey(),
initialValue: currentValue.isEmpty ? widget.initialValue : currentValue, initialValue: currentValue.isEmpty ? widget.initialValue : currentValue,
onSaved: (value) => widget.onSaved?.call(value), onSaved: (value) => widget.onSaved?.call(value),
onTap: () async { onTap: widget.onTapEnabled
String userInput = await getInputFromUser( ? () async {
widget.inputType, String userInput = await getInputFromUser(
DateFormat('dd MM yyyy HH:mm'), widget.inputType,
); DateFormat('dd MM yyyy HH:mm'),
setState(() { );
currentValue = userInput != '' ? userInput : currentValue; setState(() {
widget.onChanged?.call(userInput != '' ? userInput : currentValue); currentValue = userInput != '' ? userInput : currentValue;
}); widget.onChanged
}, ?.call(userInput != '' ? userInput : currentValue);
});
}
: null,
validator: (value) => widget.validator?.call(value), validator: (value) => widget.validator?.call(value),
decoration: widget.decoration ?? decoration: widget.decoration ??
InputDecoration( InputDecoration(

View file

@ -1,6 +1,6 @@
name: flutter_input_library name: flutter_input_library
description: A new Flutter package project. description: A new Flutter package project.
version: 2.3.0 version: 2.4.0
repository: https://github.com/Iconica-Development/flutter_input_library repository: https://github.com/Iconica-Development/flutter_input_library
environment: environment: