@@ -140,23 +140,31 @@ class FormBuilderDateTimePicker extends StatefulWidget {
140
140
141
141
class _FormBuilderDateTimePickerState extends State <FormBuilderDateTimePicker > {
142
142
bool _readonly = false ;
143
+ final GlobalKey <FormFieldState > _fieldKey = GlobalKey <FormFieldState >();
144
+
145
+ final _dateTimeFormats = {
146
+ InputType .both: DateFormat ("EEEE, MMMM d, yyyy 'at' h:mma" ),
147
+ InputType .date: DateFormat ('yyyy-MM-dd' ),
148
+ InputType .time: DateFormat ("HH:mm" ),
149
+ };
143
150
144
151
@override
145
152
void initState () {
153
+ registerFieldKey ();
146
154
_readonly =
147
155
(FormBuilder .of (context)? .readonly == true ) ? true : widget.readonly;
148
156
super .initState ();
149
157
}
150
158
151
- final _dateTimeFormats = {
152
- InputType .both: DateFormat ("EEEE, MMMM d, yyyy 'at' h:mma" ),
153
- InputType .date: DateFormat ('yyyy-MM-dd' ),
154
- InputType .time: DateFormat ("HH:mm" ),
155
- };
159
+ registerFieldKey () {
160
+ if (FormBuilder .of (context) != null )
161
+ FormBuilder .of (context).registerFieldKey (widget.attribute, _fieldKey);
162
+ }
156
163
157
164
@override
158
165
Widget build (BuildContext context) {
159
166
return DateTimePickerFormField (
167
+ key: _fieldKey,
160
168
inputType: widget.inputType,
161
169
initialValue: widget.initialValue,
162
170
format: widget.format != null
0 commit comments