GaspardMerten / date_field

Flutter DateField and DateFormField
Other
46 stars 32 forks source link

DateTimeFormField doesn't update #20

Closed danw8989 closed 3 years ago

danw8989 commented 3 years ago

Widget doesn't change its content on rebuild when initialValue changes to null.

DateTimeFormField(
                                decoration: InputDecoration(
                                  hintStyle: const TextStyle(color: Colors.black45),
                                  errorStyle: const TextStyle(color: Colors.redAccent),
                                  border: const OutlineInputBorder(),
                                  suffixIcon: IconButton(
                                    icon: const Icon(Icons.cancel),
                                    onPressed: () {
                                      _bloc.change(
                                        kontener.copyWith(
                                          dataW: null,
                                        ),
                                      );
                                    },
                                  ),
                                  labelText: 'Data przypisania',
                                ),
                                initialValue: kontener.dataW,
                                dateFormat: DateFormat.yMMMEd('pl_PL'),
                                mode: DateTimeFieldPickerMode.date,
                                onDateSelected: (value) {
                                  _bloc.change(
                                    kontener.copyWith(dataW: value),
                                  );
                                },
                                validator: (value) => value == null ? 'Wybierz datę' : null,
                              )),
GaspardMerten commented 3 years ago

You should probably use the value property!

danw8989 commented 3 years ago

But there is no value property.

 DateTimeFormField({
    Key? key,
    FormFieldSetter<DateTime>? onSaved,
    FormFieldValidator<DateTime>? validator,
    DateTime? initialValue,
    AutovalidateMode? autovalidateMode,
    bool enabled = true,
    TextStyle? dateTextStyle,
    DateFormat? dateFormat,
    DateTime? firstDate,
    DateTime? lastDate,
    DateTime? initialDate,
    ValueChanged<DateTime>? onDateSelected,
    InputDecoration? decoration,
    DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
    DatePickerMode initialDatePickerMode = DatePickerMode.day,
    DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
  })
GaspardMerten commented 3 years ago

Oh right, you can't modify the value of the form field from the widget itself since it uses the value from the form !

If you need to modify the value you can use the none-form widget which has a selectedDate attribute.

danw8989 commented 3 years ago

Ok, thank you very much for the feedback.

Mmisiek commented 1 year ago

Sorry, I have the same problem. I want to change value of displayed date on rebuild. This is not working. Are you saying that this widget supports only initial value on build but not on rebuild?