fix: 12 o'clock at noon selectable

This commit is contained in:
Kafune 2023-08-09 15:47:58 +02:00
parent a0afa5e401
commit b349078cf7
4 changed files with 15 additions and 7 deletions

View file

@ -28,4 +28,6 @@
## 2.1.0 ## 2.1.0
* make compatible with flutter 3.10 * make compatible with flutter 3.10
## 2.2.0
* Dateformat optional on input from the user, defaulting to 24 hour format

View file

@ -68,7 +68,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "2.0.0" version: "2.2.0"
flutter_lints: flutter_lints:
dependency: "direct dev" dependency: "direct dev"
description: description:

View file

@ -84,7 +84,8 @@ class _DateInputFieldState extends State<DateTimeInputField> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Future<String> getInputFromUser(FlutterFormDateTimeType inputType) async { Future<String> getInputFromUser(FlutterFormDateTimeType inputType,
[DateFormat? dateFormat]) async {
String userInput = ''; String userInput = '';
switch (inputType) { switch (inputType) {
case FlutterFormDateTimeType.date: case FlutterFormDateTimeType.date:
@ -106,8 +107,10 @@ class _DateInputFieldState extends State<DateTimeInputField> {
await getInputFromUser(FlutterFormDateTimeType.time); await getInputFromUser(FlutterFormDateTimeType.time);
if (secondInput != '') { if (secondInput != '') {
var date = widget.dateFormat.parse(value); var date = widget.dateFormat.parse(value);
var time = DateFormat('dd MM yyyy hh:mm') var time = dateFormat != null
.parse('01 01 1970 $secondInput'); ? dateFormat.parse('01 01 1970 $secondInput')
: DateFormat('dd MM yyyy HH:mm')
.parse('01 01 1970 $secondInput');
userInput = widget.dateFormat.format(DateTime( userInput = widget.dateFormat.format(DateTime(
date.year, date.year,
date.month, date.month,
@ -161,7 +164,10 @@ class _DateInputFieldState extends State<DateTimeInputField> {
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: () async {
String userInput = await getInputFromUser(widget.inputType); String userInput = await getInputFromUser(
widget.inputType,
DateFormat('dd MM yyyy HH:mm'),
);
setState(() { setState(() {
currentValue = userInput != '' ? userInput : currentValue; currentValue = userInput != '' ? userInput : currentValue;
widget.onChanged?.call(userInput != '' ? userInput : currentValue); widget.onChanged?.call(userInput != '' ? userInput : currentValue);

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.1.1 version: 2.2.0
repository: https://github.com/Iconica-Development/flutter_input_library repository: https://github.com/Iconica-Development/flutter_input_library
environment: environment: