diff --git a/CHANGELOG.md b/CHANGELOG.md index 33ca76a..9014dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,4 +30,7 @@ * make compatible with flutter 3.10 ## 2.2.0 -* Dateformat optional on input from the user, defaulting to 24 hour format \ No newline at end of file +* Dateformat optional on input from the user, defaulting to 24 hour format + + ## 2.2.1 +* Initial time optional on input from the user, defaulting to current time \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index 049f1be..3821b9e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -68,7 +68,7 @@ packages: path: ".." relative: true source: path - version: "2.2.0" + version: "2.2.1" 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 3496fd1..ce604c9 100644 --- a/lib/src/inputs/date_picker/date_picker_field.dart +++ b/lib/src/inputs/date_picker/date_picker_field.dart @@ -21,6 +21,7 @@ class DateTimeInputField extends StatefulWidget { required this.firstDate, required this.lastDate, this.initialDate, + this.initialTime, this.initialDateTimeRange, this.initialValue, this.onChanged, @@ -40,6 +41,7 @@ class DateTimeInputField extends StatefulWidget { final DateTime? firstDate; final DateTime? lastDate; final DateTime? initialDate; + final TimeOfDay? initialTime; final DateTimeRange? initialDateTimeRange; final IconData? icon; final Widget? label; @@ -58,6 +60,7 @@ class _DateInputFieldState extends State { late final DateTime lastDate; late final DateTime initialDate; late final DateTimeRange initialDateRange; + late final TimeOfDay? initialTime; String currentValue = ''; @override @@ -82,6 +85,8 @@ class _DateInputFieldState extends State { super.initState(); } + TimeOfDay get initialTimeOfDay => widget.initialTime ?? TimeOfDay.now(); + @override Widget build(BuildContext context) { Future getInputFromUser(FlutterFormDateTimeType inputType, @@ -137,20 +142,20 @@ class _DateInputFieldState extends State { break; case FlutterFormDateTimeType.time: userInput = await showTimePicker( - initialEntryMode: widget.timePickerEntryMode, - builder: (BuildContext context, Widget? child) { - return MediaQuery( - data: MediaQuery.of(context) - .copyWith(alwaysUse24HourFormat: true), - child: child!, - ); - }, - context: context, - initialTime: TimeOfDay.now()) - .then((value) => value == null - ? '' - : MaterialLocalizations.of(context) - .formatTimeOfDay(value, alwaysUse24HourFormat: true)); + initialEntryMode: widget.timePickerEntryMode, + builder: (BuildContext context, Widget? child) { + return MediaQuery( + data: MediaQuery.of(context) + .copyWith(alwaysUse24HourFormat: true), + child: child!, + ); + }, + context: context, + initialTime: initialTimeOfDay, + ).then((value) => value == null + ? '' + : MaterialLocalizations.of(context) + .formatTimeOfDay(value, alwaysUse24HourFormat: true)); } return userInput; } diff --git a/pubspec.yaml b/pubspec.yaml index 8512c42..83eb2c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_input_library description: A new Flutter package project. -version: 2.2.0 +version: 2.2.1 repository: https://github.com/Iconica-Development/flutter_input_library environment: