@@ -184,7 +184,7 @@ class FormBuilderDateTimePicker extends StatefulWidget {
184
184
this .cursorRadius,
185
185
this .cursorColor,
186
186
this .keyboardAppearance,
187
- this .textCapitalization,
187
+ this .textCapitalization = TextCapitalization .none ,
188
188
this .strutStyle,
189
189
});
190
190
@@ -215,6 +215,7 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
215
215
(_formState.initialValue.containsKey (widget.attribute)
216
216
? _formState.initialValue[widget.attribute]
217
217
: null );
218
+ _readOnly = (_formState? .readOnly == true ) ? true : widget.readOnly;
218
219
super .initState ();
219
220
}
220
221
@@ -226,8 +227,6 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
226
227
227
228
@override
228
229
Widget build (BuildContext context) {
229
- _readOnly = (_formState? .readOnly == true ) ? true : widget.readOnly;
230
-
231
230
return DateTimeField (
232
231
key: _fieldKey,
233
232
initialValue: _initialValue,
@@ -248,16 +247,16 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
248
247
}
249
248
return null ;
250
249
},
251
- onShowPicker: (ctx, time ) async {
250
+ onShowPicker: (context, currentValue ) async {
252
251
switch (widget.inputType) {
253
252
case InputType .date:
254
- return _showDatePicker (context);
253
+ return _showDatePicker (context, currentValue );
255
254
case InputType .time:
256
- return DateTimeField .convert (await _showTimePicker (context));
255
+ return DateTimeField .convert (await _showTimePicker (context, currentValue ));
257
256
case InputType .both:
258
- final date = await _showDatePicker (context);
257
+ final date = await _showDatePicker (context, currentValue );
259
258
if (date != null ) {
260
- final time = await _showTimePicker (context);
259
+ final time = await _showTimePicker (context, currentValue );
261
260
return DateTimeField .combine (date, time);
262
261
}
263
262
return _fieldKey.currentState.value ?? _initialValue;
@@ -302,7 +301,7 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
302
301
);
303
302
}
304
303
305
- Future <DateTime > _showDatePicker (BuildContext context) {
304
+ Future <DateTime > _showDatePicker (BuildContext context, DateTime currentValue ) {
306
305
if (widget.datePicker != null ) {
307
306
return widget.datePicker (context);
308
307
} else {
@@ -311,17 +310,17 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
311
310
selectableDayPredicate: widget.selectableDayPredicate,
312
311
initialDatePickerMode:
313
312
widget.initialDatePickerMode ?? DatePickerMode .day,
314
- initialDate: widget.initialDate ,
315
- firstDate: widget.firstDate,
316
- lastDate: widget.lastDate);
313
+ initialDate: currentValue ?? DateTime . now () ,
314
+ firstDate: widget.firstDate ?? DateTime ( 1900 ) ,
315
+ lastDate: widget.lastDate ?? DateTime ( 2100 ) );
317
316
}
318
317
}
319
318
320
- Future <TimeOfDay > _showTimePicker (BuildContext context) {
319
+ Future <TimeOfDay > _showTimePicker (BuildContext context, DateTime currentValue ) {
321
320
if (widget.timePicker != null ) {
322
321
return widget.timePicker (context);
323
322
} else {
324
- return showTimePicker (context: context, initialTime: widget.initialTime );
323
+ return showTimePicker (context: context, initialTime: TimeOfDay . fromDateTime (currentValue ?? DateTime . now ()) );
325
324
}
326
325
}
327
326
}
0 commit comments