datetime_picker_formfield
datetime_picker_formfield copied to clipboard
🐛 Bug on Windows version - time returned is out by one hour
We're expanding our app to include Desktop versions.
Unforutently the DateTimeField is failing with an issue that seems to be Windows-specific.
When picking a time it's displaying the selected time but returns a time one hour in the future (on the 2nd of Jan 1970)
For example 11:34 AM becomes => 00:34 am (1970-01-02 00:34:00.000)
This is not affecting Android or iOS builds and seems to be specific to Windows.
implementation code looks like this:
return DateTimeField(
format: DateFormat(getFormatString(widget.definition.inputType)),
validator: getValidator(),
decoration: InputDecoration(
labelText: widget.definition.name,
floatingLabelBehavior: FloatingLabelBehavior.never),
onChanged: dateUpdated,
autofocus: false,
initialValue: widget.data,
onShowPicker: (BuildContext context, DateTime? currentValue) async {
DateTime? date;
if (<InputType>[InputType.date, InputType.both]
.contains(widget.definition.inputType)) {
date = await showDatePicker(
context: context,
firstDate: DateTime(1900),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100));
if (date == null) {
return currentValue;
}
}
TimeOfDay? time;
if (<InputType>[InputType.time, InputType.both]
.contains(widget.definition.inputType)) {
time = await showTimePicker(
context: context,
initialEntryMode: TimePickerEntryMode.dial,
initialTime: TimeOfDay.fromDateTime(currentValue ?? DateTime.now()),
);
if (time == null) {
return currentValue;
}
}
switch (widget.definition.inputType) {
case InputType.date:
return date;
case InputType.time:
return DateTimeField.combine(DateTime(0), time);
case InputType.both:
default:
return DateTimeField.combine(date!, time);
}
},
);