GaspardMerten / date_field

Flutter DateField and DateFormField
Other
46 stars 32 forks source link

feat(date_form_field): add a selectedDate #33

Closed Pierre-Monier closed 2 years ago

Pierre-Monier commented 2 years ago

I add a selectedDate attribute on the DateTimeFormField class. In one project I must change the displayed value when a variable change, maybe this can be useful to other people

GaspardMerten commented 2 years ago

Hello @Pierre-Monier, if I understood your goal correctly, you want to change the selected value of the DateTimeFormField widget without the user input.

If that's the case, please note that the architecture of the widget is the default one for form fields in Flutter. You can change the value manually by using a GlobalKey.


  final fieldKey = GlobalKey<FormFieldState<DateTime>>();
 void changeDate() =>   fieldKey.currentState?.didChange([NEW_VALUE]);
 build(...) {
    ...DateTimeFormField(key: fieldKey, ...)...

Did I miss something?

Pierre-Monier commented 2 years ago

Hum I see, I can make it works that way to. I will close my PR