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
* 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: ".."
relative: true
source: path
version: "2.0.0"
version: "2.2.0"
flutter_lints:
dependency: "direct dev"
description:

View file

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

View file

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