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

(3.3.4) FormBuilderDateTimePicker ignoring initialDate #108

Closed
abhinavc opened this issue Aug 9, 2019 · 6 comments
Closed

(3.3.4) FormBuilderDateTimePicker ignoring initialDate #108

abhinavc opened this issue Aug 9, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@abhinavc
Copy link

abhinavc commented Aug 9, 2019

Hi Danvick,

Noticed a possible breaking change.

Passing initialDate: DateTime.tryParse("20000101"), for example, in the constructor has no effect. The date picker still open at current date.

And if one passes a lastDate that is before today, then one gets an
!initialDate.isAfter(lastDate) assertion error from within date_picker.dart

The problem seems to be here in form_builder_date_time_picker.dart

Future<DateTime> _showDatePicker(
     ....
      return showDatePicker(
          context: context,
          ....
          initialDate: currentValue ?? DateTime.now(),
          firstDate: widget.firstDate ?? DateTime(1900),
          lastDate: widget.lastDate ?? DateTime(2100));
  }

I think initialDate: (currentValue ?? widget.initialDate) ?? DateTime.now() is what's required. But you can confirm.

Thanks
Abhinav.

@danvick danvick added the bug Something isn't working label Aug 9, 2019
@danvick
Copy link
Collaborator

danvick commented Aug 9, 2019

Thank you for bringing this to our attention.

@userone912
Copy link

userone912 commented Aug 9, 2019

Hi,
The initialValue also not working in FormBuilderDateTimePicker. The value set in initialValue i.e {'date':DateTime.utc(2010,1,1)} were successfully assigned to the attribute (it is not null) but not printed in the field, it just blank.

Edited :
...and when _formkey.currentstate.reset() fired, the field filled with initialValue.

@andyd1
Copy link

andyd1 commented Aug 19, 2019

Looks like the culprit is that the value of the text editing controller is not being set on intiState.

Adding the following got me back up and running:

In initState(), right after
_textFieldController = widget.controller ?? TextEditingController();

widget.initialValue == null ? "" :
widget.format == null ? DateFormat("EEEE, MMMM d, yyyy 'at' h:mma").format(
    widget.initialValue) :
widget.format.format(widget.initialValue));

I'm sure there is a more elegant way to do this - also, I have a check box in my app to show or hide the date, that logic seems to be not working at the moment.

@abhinavc
Copy link
Author

This bug has come sometime after 3.0.1. Hence I am hoping it gets fixed here itself.

@danvick
Copy link
Collaborator

danvick commented Aug 21, 2019

Hi @abhinavc,
Kindly confirm that this issue is fixed as of v3.4.0.
Feel free to reopen the issue if not.

@abhinavc
Copy link
Author

Hi Danvick,
Tried 3.4.1 and it seems the issue still remains.
firstDate is honored. lastDate is also honored, though specifying one can lead to an assertion
error because initialDate still seems to be set to today's date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants