Skip to content

Commit 2cefe57

Browse files
committed
Fixed a few bugs in DateTimePicker
1 parent 542c41e commit 2cefe57

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class FormBuilderDateTimePicker extends StatefulWidget {
184184
this.cursorRadius,
185185
this.cursorColor,
186186
this.keyboardAppearance,
187-
this.textCapitalization,
187+
this.textCapitalization = TextCapitalization.none,
188188
this.strutStyle,
189189
});
190190

@@ -215,6 +215,7 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
215215
(_formState.initialValue.containsKey(widget.attribute)
216216
? _formState.initialValue[widget.attribute]
217217
: null);
218+
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
218219
super.initState();
219220
}
220221

@@ -226,8 +227,6 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
226227

227228
@override
228229
Widget build(BuildContext context) {
229-
_readOnly = (_formState?.readOnly == true) ? true : widget.readOnly;
230-
231230
return DateTimeField(
232231
key: _fieldKey,
233232
initialValue: _initialValue,
@@ -248,16 +247,16 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
248247
}
249248
return null;
250249
},
251-
onShowPicker: (ctx, time) async {
250+
onShowPicker: (context, currentValue) async {
252251
switch (widget.inputType) {
253252
case InputType.date:
254-
return _showDatePicker(context);
253+
return _showDatePicker(context, currentValue);
255254
case InputType.time:
256-
return DateTimeField.convert(await _showTimePicker(context));
255+
return DateTimeField.convert(await _showTimePicker(context, currentValue));
257256
case InputType.both:
258-
final date = await _showDatePicker(context);
257+
final date = await _showDatePicker(context, currentValue);
259258
if (date != null) {
260-
final time = await _showTimePicker(context);
259+
final time = await _showTimePicker(context, currentValue);
261260
return DateTimeField.combine(date, time);
262261
}
263262
return _fieldKey.currentState.value ?? _initialValue;
@@ -302,7 +301,7 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
302301
);
303302
}
304303

305-
Future<DateTime> _showDatePicker(BuildContext context) {
304+
Future<DateTime> _showDatePicker(BuildContext context, DateTime currentValue) {
306305
if (widget.datePicker != null) {
307306
return widget.datePicker(context);
308307
} else {
@@ -311,17 +310,17 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
311310
selectableDayPredicate: widget.selectableDayPredicate,
312311
initialDatePickerMode:
313312
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));
317316
}
318317
}
319318

320-
Future<TimeOfDay> _showTimePicker(BuildContext context) {
319+
Future<TimeOfDay> _showTimePicker(BuildContext context, DateTime currentValue) {
321320
if (widget.timePicker != null) {
322321
return widget.timePicker(context);
323322
} else {
324-
return showTimePicker(context: context, initialTime: widget.initialTime);
323+
return showTimePicker(context: context, initialTime: TimeOfDay.fromDateTime(currentValue ?? DateTime.now()));
325324
}
326325
}
327326
}

0 commit comments

Comments
 (0)