Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug on Windows version - time returned is out by one hour #133

Open
NickoftheSouth opened this issue Sep 8, 2022 · 0 comments
Open

Comments

@NickoftheSouth
Copy link

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);
        }
      },
    );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant