flutter_form_builder
flutter_form_builder copied to clipboard
[FormBuilderCheckboxGroup] patchValue don't work
I am trying to set values with patchvalue
like this.
var state = searchModel.value.formKeys.formKey.currentState;
state.patchValue({
"map_field": searchModel.value.address ?? "",
"noOfROoms": searchModel.value.noOfRoom,
"price_upper": searchModel.value.priceUpper,
"price_lower": searchModel.value.priceLower,
"Type": searchModel.value.type,
"water": searchModel.value.water,
"parking": searchModel.value.parkings,
});
parking is a FormBuilderCheckboxGroup<Parking>
and the searchModel.value.parkings
is of type List<Parking>
everything except "parking" is displaying correct values. Parking widget should have checked state for those values. But it is not showing those selected states. didChange(val)
does not seems to get the desired result.
state.fields['parking'].didChange(searchModel.value.parkings);
But then, when I print the value, state.fields['parking'].value
after patching. This is giving the correct values. Also onChange in the widget is getting called with the correct given values. I gues that means values are been set. But the check box is not selected as it should have been. However If I give the same value as initialValue, check box are selected as expected.
Am I doing anything wrong here?
UI is not being updated I think. I have similar issue and found no workaround to it.
I am using this in production. I got no option but to hide this feature since I cannot find any workaround. @danvick Is there any work around for this.
I was trying to patch values when initializing the page and ran into the same problem. I solved this by conditionally setting the initial value and now the UI is displaying correctly. Maybe you could try my solution and call setState to rebuild the UI.
This still a issue with the lasted version?
Due to lack of response and an old error, I will close this issue. If the bug still exists, feel free to open a new issue