Flutter_form_builder: [Urgent] Hidden form field data is not saved

Created on 10 Nov 2020  Â·  3Comments  Â·  Source: danvick/flutter_form_builder

I am using flutter_form_builder: ^3.14.1

We have requirement to put hidden fields in form and on submit send hidden fields value to server. But issue is when I put any widget e.g FormBuilderCheckbox in Visibility widget, set visible false then on submit FormBuilderCheckbox value is not saved in form

e.g
Widget makeCheckBoxWidget(FormElement element){
return Visibility(
visible: false,
child: FormBuilderCheckbox(
attribute: "check",
initialValue: false,
leadingInput: true,
readOnly: element.isDisabled,
decoration:InputDecoration(contentPadding: EdgeInsets.zero,border:InputBorder.none),
label: Align(
child: Text(element.label,style: Theme.of(context).textTheme.bodyText2,),
alignment: Alignment(-1.1, 0),
),
validators: getValidation(element),
),
);
}

Flutter Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.3, on Mac OS X 10.14.6 18G3020, locale en-IN)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.5)
[✓] Connected device (1 available)

• No issues found!

question

Most helpful comment

Okay. I have found the solution. In Visibility widget you need to set maintainState: true property in Visibility widget which maintain states of child widgets when child widgets are not visible.

Widget makeCheckBoxWidget(FormElement element){
return Visibility(
visible: false,
maintainState: true,
child: FormBuilderCheckbox(
attribute: "check",
initialValue: false,
leadingInput: true,
readOnly: element.isDisabled,
decoration:InputDecoration(contentPadding: EdgeInsets.zero,border:InputBorder.none),
label: Align(
child: Text(element.label,style: Theme.of(context).textTheme.bodyText2,),
alignment: Alignment(-1.1, 0),
),
validators: getValidation(element),
),
);
}

Please close this issue.

All 3 comments

Okay. I have found the solution. In Visibility widget you need to set maintainState: true property in Visibility widget which maintain states of child widgets when child widgets are not visible.

Widget makeCheckBoxWidget(FormElement element){
return Visibility(
visible: false,
maintainState: true,
child: FormBuilderCheckbox(
attribute: "check",
initialValue: false,
leadingInput: true,
readOnly: element.isDisabled,
decoration:InputDecoration(contentPadding: EdgeInsets.zero,border:InputBorder.none),
label: Align(
child: Text(element.label,style: Theme.of(context).textTheme.bodyText2,),
alignment: Alignment(-1.1, 0),
),
validators: getValidation(element),
),
);
}

Please close this issue.

@SachinTanpure please close the issue if it is resolved

I'm closing this since it looks resolved.

Was this page helpful?
0 / 5 - 0 ratings