Skip to content

Commit 4a0b784

Browse files
committed
Fix bug where onChange in FormBuilderDateTimePicker doesn't fire when cleared bug. Closes #254
1 parent 40cfc4b commit 4a0b784

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
281281
return null;
282282
},
283283
onShowPicker: _onShowPicker,
284-
// onChanged: widget.onChanged,
284+
onChanged: (val) {
285+
if (widget.onChanged != null)
286+
widget.onChanged(val);
287+
},
285288
autovalidate: widget.autovalidate,
286289
resetIcon: widget.resetIcon,
287290
textDirection: widget.textDirection,
@@ -344,8 +347,6 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
344347
}
345348
newValue = newValue ?? currentValue;
346349
_fieldKey.currentState.didChange(newValue);
347-
if (widget.onChanged != null)
348-
widget.onChanged(_fieldKey.currentState.value);
349350
return newValue;
350351
}
351352

@@ -355,14 +356,15 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
355356
return widget.datePicker(context);
356357
} else {
357358
return showDatePicker(
358-
context: context,
359-
selectableDayPredicate: widget.selectableDayPredicate,
360-
initialDatePickerMode:
361-
widget.initialDatePickerMode ?? DatePickerMode.day,
362-
// ignore: deprecated_member_use_from_same_package
363-
initialDate: currentValue ?? widget.initialDate ?? DateTime.now(),
364-
firstDate: widget.firstDate ?? DateTime(1900),
365-
lastDate: widget.lastDate ?? DateTime(2100));
359+
context: context,
360+
selectableDayPredicate: widget.selectableDayPredicate,
361+
initialDatePickerMode:
362+
widget.initialDatePickerMode ?? DatePickerMode.day,
363+
// ignore: deprecated_member_use_from_same_package
364+
initialDate: currentValue ?? widget.initialDate ?? DateTime.now(),
365+
firstDate: widget.firstDate ?? DateTime(1900),
366+
lastDate: widget.lastDate ?? DateTime(2100),
367+
);
366368
}
367369
}
368370

@@ -378,12 +380,14 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
378380
? TimeOfDay.fromDateTime(currentValue)
379381
// ignore: deprecated_member_use_from_same_package
380382
: widget.initialTime ?? TimeOfDay.fromDateTime(DateTime.now()),
381-
).then((result) {
382-
return result ??
383-
(currentValue != null
384-
? TimeOfDay.fromDateTime(currentValue)
385-
: null);
386-
});
383+
).then(
384+
(result) {
385+
return result ??
386+
(currentValue != null
387+
? TimeOfDay.fromDateTime(currentValue)
388+
: null);
389+
},
390+
);
387391
}
388392
}
389393
}

0 commit comments

Comments
 (0)