diff --git a/CHANGELOG.md b/CHANGELOG.md index 187fe9c..33ca76a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,4 +28,6 @@ ## 2.1.0 * make compatible with flutter 3.10 - \ No newline at end of file + + ## 2.2.0 +* Dateformat optional on input from the user, defaulting to 24 hour format \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index c3c1abd..049f1be 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "2.0.0" + version: "2.2.0" flutter_lints: dependency: "direct dev" description: diff --git a/lib/src/inputs/date_picker/date_picker_field.dart b/lib/src/inputs/date_picker/date_picker_field.dart index 0d62580..3496fd1 100644 --- a/lib/src/inputs/date_picker/date_picker_field.dart +++ b/lib/src/inputs/date_picker/date_picker_field.dart @@ -84,7 +84,8 @@ class _DateInputFieldState extends State { @override Widget build(BuildContext context) { - Future getInputFromUser(FlutterFormDateTimeType inputType) async { + Future getInputFromUser(FlutterFormDateTimeType inputType, + [DateFormat? dateFormat]) async { String userInput = ''; switch (inputType) { case FlutterFormDateTimeType.date: @@ -106,8 +107,10 @@ class _DateInputFieldState extends State { 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 { 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); diff --git a/pubspec.yaml b/pubspec.yaml index 59b6795..8512c42 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: