GaspardMerten / date_field

Flutter DateField and DateFormField
Other
46 stars 32 forks source link

Initial dateTime is not selected properly #19

Closed Ranko97 closed 3 years ago

Ranko97 commented 3 years ago

When I have lastDate provided (e.g. user should have 18 years), initialDateTime would be set to DateTime.now(), which causes errors. Current workaround is to provide initialDate in correct range, but this means date field would be preselected.

This issue can be solved by changing the default initial date value from DateTime.now() to lastDate.

So, this would be the correct code: final DateTime initialDateTime = selectedDate ?? lastDate; , on line 86, function _selectDate, in file field.dart.

From my limited testing, this would not cause any additional issues.

If there is another way to solve this issue, please let me know.

GaspardMerten commented 3 years ago

Hello @Ranko97,

What do you think of the following behaviour:

If the current date (datetime.now) is included in the firstDate - lastDate range, it is used as default. Otherwise, we use the lastDate.

Good for you?

Ranko97 commented 3 years ago

Hello @GaspardMerten ,

Yes, I think that should solve this issue.

GaspardMerten commented 3 years ago

This is now a solved issue in the latest version (2.1.2)

The new argument is called initialDate.

Thank you for reporting the issue.