From 1c221fadf9444894515e86fa523080bc3cf22782 Mon Sep 17 00:00:00 2001 From: Jacques Date: Thu, 26 Oct 2023 16:12:37 +0200 Subject: [PATCH] Added the ability to disable onTap of DateTimePicker --- CHANGELOG.md | 6 ++++- lib/src/inputs/date_picker/date_picker.dart | 6 +++++ .../inputs/date_picker/date_picker_field.dart | 25 +++++++++++-------- pubspec.yaml | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac7c80..821059d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,4 +36,8 @@ * Initial time optional on input from the user, defaulting to current time ## 2.3.0 -* The ability to set the enabled parameter of TextFormFields \ No newline at end of file +* 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 \ No newline at end of file diff --git a/lib/src/inputs/date_picker/date_picker.dart b/lib/src/inputs/date_picker/date_picker.dart index 0d64726..b041a39 100644 --- a/lib/src/inputs/date_picker/date_picker.dart +++ b/lib/src/inputs/date_picker/date_picker.dart @@ -34,6 +34,8 @@ class FlutterFormInputDateTime extends StatelessWidget { this.validator, this.autovalidateMode = AutovalidateMode.disabled, this.timePickerEntryMode = TimePickerEntryMode.dial, + this.enabled = true, + this.onTapEnabled = true, }) : super( key: key, ); @@ -55,6 +57,8 @@ class FlutterFormInputDateTime extends StatelessWidget { final void Function(String?)? onChanged; final AutovalidateMode autovalidateMode; final TimePickerEntryMode timePickerEntryMode; + final bool enabled; + final bool onTapEnabled; @override Widget build(BuildContext context) { @@ -77,6 +81,8 @@ class FlutterFormInputDateTime extends StatelessWidget { onSaved: (value) => onSaved?.call(value), showIcon: showIcon, timePickerEntryMode: timePickerEntryMode, + enabled: enabled, + onTapEnabled: onTapEnabled, ); } } diff --git a/lib/src/inputs/date_picker/date_picker_field.dart b/lib/src/inputs/date_picker/date_picker_field.dart index a98c004..b430339 100644 --- a/lib/src/inputs/date_picker/date_picker_field.dart +++ b/lib/src/inputs/date_picker/date_picker_field.dart @@ -30,6 +30,7 @@ class DateTimeInputField extends StatefulWidget { required this.timePickerEntryMode, required this.style, this.enabled = true, + this.onTapEnabled = true, }) : super( key: key, ); @@ -52,6 +53,7 @@ class DateTimeInputField extends StatefulWidget { final void Function(String?)? onChanged; final TimePickerEntryMode timePickerEntryMode; final bool enabled; + final bool onTapEnabled; @override State createState() => _DateInputFieldState(); @@ -174,16 +176,19 @@ class _DateInputFieldState extends State { key: UniqueKey(), initialValue: currentValue.isEmpty ? widget.initialValue : currentValue, onSaved: (value) => widget.onSaved?.call(value), - onTap: () async { - String userInput = await getInputFromUser( - widget.inputType, - DateFormat('dd MM yyyy HH:mm'), - ); - setState(() { - currentValue = userInput != '' ? userInput : currentValue; - widget.onChanged?.call(userInput != '' ? userInput : currentValue); - }); - }, + onTap: widget.onTapEnabled + ? () async { + String userInput = await getInputFromUser( + widget.inputType, + DateFormat('dd MM yyyy HH:mm'), + ); + setState(() { + currentValue = userInput != '' ? userInput : currentValue; + widget.onChanged + ?.call(userInput != '' ? userInput : currentValue); + }); + } + : null, validator: (value) => widget.validator?.call(value), decoration: widget.decoration ?? InputDecoration( diff --git a/pubspec.yaml b/pubspec.yaml index 12b5769..bd6d7d9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_input_library description: A new Flutter package project. -version: 2.3.0 +version: 2.4.0 repository: https://github.com/Iconica-Development/flutter_input_library environment: