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
|
## 1.0.3
|
||||||
|
|
||||||
* add FocusNode option for input fields
|
* 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'),
|
const Text('FlutterFormInputDateTime'),
|
||||||
FlutterFormInputDateTime(
|
FlutterFormInputDateTime(
|
||||||
decoration: const InputDecoration(label: Text('test')),
|
decoration: const InputDecoration(label: Text('test')),
|
||||||
inputType: FlutterFormDateTimeType.time,
|
autovalidateMode: AutovalidateMode.always,
|
||||||
dateFormat: DateFormat('HH:mm'),
|
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) {
|
onChanged: (v) {
|
||||||
debugPrint('Date changed to $v');
|
debugPrint('Date changed to $v');
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,7 +61,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "1.0.3"
|
version: "1.0.4"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -15,8 +15,8 @@ enum FlutterFormDateTimeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
class FlutterFormInputDateTime extends ConsumerWidget {
|
class FlutterFormInputDateTime extends ConsumerWidget {
|
||||||
const FlutterFormInputDateTime({
|
const FlutterFormInputDateTime(
|
||||||
this.decoration,
|
{this.decoration,
|
||||||
Key? key,
|
Key? key,
|
||||||
this.label,
|
this.label,
|
||||||
this.showIcon = true,
|
this.showIcon = true,
|
||||||
|
@ -31,7 +31,8 @@ class FlutterFormInputDateTime extends ConsumerWidget {
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.onSaved,
|
this.onSaved,
|
||||||
this.validator,
|
this.validator,
|
||||||
}) : super(
|
this.autovalidateMode = AutovalidateMode.disabled})
|
||||||
|
: super(
|
||||||
key: key,
|
key: key,
|
||||||
);
|
);
|
||||||
final InputDecoration? decoration;
|
final InputDecoration? decoration;
|
||||||
|
@ -48,11 +49,14 @@ class FlutterFormInputDateTime extends ConsumerWidget {
|
||||||
final String? Function(String?)? validator;
|
final String? Function(String?)? validator;
|
||||||
final void Function(String?)? onSaved;
|
final void Function(String?)? onSaved;
|
||||||
final void Function(String?)? onChanged;
|
final void Function(String?)? onChanged;
|
||||||
|
final AutovalidateMode autovalidateMode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return DateTimeInputField(
|
return DateTimeInputField(
|
||||||
decoration: decoration,
|
decoration: decoration,
|
||||||
|
autovalidateMode: autovalidateMode,
|
||||||
|
validator: validator,
|
||||||
label: label,
|
label: label,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
firstDate: firstDate,
|
firstDate: firstDate,
|
||||||
|
|
|
@ -14,6 +14,7 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
||||||
this.decoration,
|
this.decoration,
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.inputType,
|
required this.inputType,
|
||||||
|
required this.autovalidateMode,
|
||||||
this.label,
|
this.label,
|
||||||
this.showIcon = true,
|
this.showIcon = true,
|
||||||
this.icon,
|
this.icon,
|
||||||
|
@ -30,6 +31,7 @@ class DateTimeInputField extends ConsumerStatefulWidget {
|
||||||
key: key,
|
key: key,
|
||||||
);
|
);
|
||||||
final InputDecoration? decoration;
|
final InputDecoration? decoration;
|
||||||
|
final AutovalidateMode autovalidateMode;
|
||||||
final FlutterFormDateTimeType inputType;
|
final FlutterFormDateTimeType inputType;
|
||||||
final DateFormat dateFormat;
|
final DateFormat dateFormat;
|
||||||
final bool showIcon;
|
final bool showIcon;
|
||||||
|
@ -100,7 +102,16 @@ class _DateInputFieldState extends ConsumerState<DateTimeInputField> {
|
||||||
String secondInput =
|
String secondInput =
|
||||||
await getInputFromUser(FlutterFormDateTimeType.time);
|
await getInputFromUser(FlutterFormDateTimeType.time);
|
||||||
if (secondInput != '') {
|
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(
|
return TextFormField(
|
||||||
|
autovalidateMode: widget.autovalidateMode,
|
||||||
keyboardType: TextInputType.none,
|
keyboardType: TextInputType.none,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
key: Key(currentValue.toString()),
|
key: Key(currentValue.toString()),
|
||||||
|
|
|
@ -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: 1.0.3
|
version: 1.0.4
|
||||||
repository: https://github.com/Iconica-Development/flutter_input_library
|
repository: https://github.com/Iconica-Development/flutter_input_library
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Reference in a new issue