mirror of
https://github.com/Iconica-Development/flutter_input_library.git
synced 2025-05-18 17:03:45 +02:00
fix date-time format and validator
This commit is contained in:
parent
76293bd67e
commit
906e92b936
6 changed files with 51 additions and 23 deletions
|
@ -13,3 +13,6 @@
|
|||
## 1.0.3
|
||||
|
||||
* add FocusNode option for input fields
|
||||
|
||||
## 1.0.4
|
||||
* fix datetimepicker format and validator
|
||||
|
|
|
@ -62,8 +62,17 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
const Text('FlutterFormInputDateTime'),
|
||||
FlutterFormInputDateTime(
|
||||
decoration: const InputDecoration(label: Text('test')),
|
||||
inputType: FlutterFormDateTimeType.time,
|
||||
dateFormat: DateFormat('HH:mm'),
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
validator: (p0) {
|
||||
if (p0 == null || p0.isEmpty) return null;
|
||||
return DateFormat('dd/MMMM/yyyy HH:mm')
|
||||
.parse(p0)
|
||||
.isAfter(DateTime.now())
|
||||
? null
|
||||
: 'Date must be in the future';
|
||||
},
|
||||
inputType: FlutterFormDateTimeType.dateTime,
|
||||
dateFormat: DateFormat('dd/MMMM/yyyy HH:mm'),
|
||||
onChanged: (v) {
|
||||
debugPrint('Date changed to $v');
|
||||
},
|
||||
|
|
|
@ -61,7 +61,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.3"
|
||||
version: "1.0.4"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
|
|
@ -15,23 +15,24 @@ enum FlutterFormDateTimeType {
|
|||
}
|
||||
|
||||
class FlutterFormInputDateTime extends ConsumerWidget {
|
||||
const FlutterFormInputDateTime({
|
||||
this.decoration,
|
||||
Key? key,
|
||||
this.label,
|
||||
this.showIcon = true,
|
||||
required this.inputType,
|
||||
required this.dateFormat,
|
||||
this.firstDate,
|
||||
this.lastDate,
|
||||
this.initialDate,
|
||||
this.initialDateTimeRange,
|
||||
this.icon = Icons.calendar_today,
|
||||
this.initialValue,
|
||||
this.onChanged,
|
||||
this.onSaved,
|
||||
this.validator,
|
||||
}) : super(
|
||||
const FlutterFormInputDateTime(
|
||||
{this.decoration,
|
||||
Key? key,
|
||||
this.label,
|
||||
this.showIcon = true,
|
||||
required this.inputType,
|
||||
required this.dateFormat,
|
||||
this.firstDate,
|
||||
this.lastDate,
|
||||
this.initialDate,
|
||||
this.initialDateTimeRange,
|
||||
this.icon = Icons.calendar_today,
|
||||
this.initialValue,
|
||||
this.onChanged,
|
||||
this.onSaved,
|
||||
this.validator,
|
||||
this.autovalidateMode = AutovalidateMode.disabled})
|
||||
: super(
|
||||
key: key,
|
||||
);
|
||||
final InputDecoration? decoration;
|
||||
|
@ -48,11 +49,14 @@ class FlutterFormInputDateTime extends ConsumerWidget {
|
|||
final String? Function(String?)? validator;
|
||||
final void Function(String?)? onSaved;
|
||||
final void Function(String?)? onChanged;
|
||||
final AutovalidateMode autovalidateMode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return DateTimeInputField(
|
||||
decoration: decoration,
|
||||
autovalidateMode: autovalidateMode,
|
||||
validator: validator,
|
||||
label: label,
|
||||
icon: icon,
|
||||
firstDate: firstDate,
|
||||
|
|
|
@ -14,6 +14,7 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
|||
this.decoration,
|
||||
Key? key,
|
||||
required this.inputType,
|
||||
required this.autovalidateMode,
|
||||
this.label,
|
||||
this.showIcon = true,
|
||||
this.icon,
|
||||
|
@ -30,6 +31,7 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
|||
key: key,
|
||||
);
|
||||
final InputDecoration? decoration;
|
||||
final AutovalidateMode autovalidateMode;
|
||||
final FlutterFormDateTimeType inputType;
|
||||
final DateFormat dateFormat;
|
||||
final bool showIcon;
|
||||
|
@ -100,7 +102,16 @@ class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
|||
String secondInput =
|
||||
await getInputFromUser(FlutterFormDateTimeType.time);
|
||||
if (secondInput != '') {
|
||||
userInput = '$value $secondInput';
|
||||
var date = widget.dateFormat.parse(value);
|
||||
var time = DateFormat('dd MM yyyy hh:mm')
|
||||
.parse('01 01 1970 $secondInput');
|
||||
userInput = widget.dateFormat.format(DateTime(
|
||||
date.year,
|
||||
date.month,
|
||||
date.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -138,6 +149,7 @@ class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
|||
}
|
||||
|
||||
return TextFormField(
|
||||
autovalidateMode: widget.autovalidateMode,
|
||||
keyboardType: TextInputType.none,
|
||||
readOnly: true,
|
||||
key: Key(currentValue.toString()),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_input_library
|
||||
description: A new Flutter package project.
|
||||
version: 1.0.3
|
||||
version: 1.0.4
|
||||
repository: https://github.com/Iconica-Development/flutter_input_library
|
||||
|
||||
environment:
|
||||
|
|
Loading…
Reference in a new issue