flutter_form_builder
flutter_form_builder copied to clipboard
dynamically add/remove widget with form_builder fields
How to add and remove widgets dynamically on a form? with unique names and correct deletion. I do not normally delete elements. In addition, after deleting, you need to double-click on the plus to add the item.
i tried
-
in _PersonalState i create list widget static List<Widget> ws=List.empty(growable: true); int _numparents=0;
-
i create class
class Parents extends StatefulWidget { const Parents({Key? key,required int this.id}) : super(key: key); final int id;
@override _ParentsState createState() => _ParentsState(); }
class _ParentsState extends State<Parents> { @override Widget build(BuildContext context) { return Column( children: [ ElevatedButton(onPressed: () { int _i=0; for (var element in _PersonalState.ps) { { if (element.id==widget.id) { _PersonalState.ps.removeAt(_i); break;} _i++; }; }, child:Text("-")), FormBuilderTextField( initialValue: widget.id.toString(),
name: 'whopass'+widget.id.toString(),
),
],
);
} } 3) and in buildwidget i create adding button
ElevatedButton(onPressed: () {setState(() { _numparents++; _ParentsWidgets.add(Parents(id:_numparents));} });},child:Text("+"))
registerField and removeInternalFieldValue from formKey currentState does not satisfy your situation?
registerFieldandremoveInternalFieldValuefromformKeycurrentStatedoes not satisfy your situation?
Author like you should be banned on Flutter, your answer is always the same on different questions, the worst thing is, it's non-sense, not useful and not testable, I hope this will be your last package.
registerFieldandremoveInternalFieldValuefromformKeycurrentStatedoes not satisfy your situation?
For all who want to know how to use registerField, you have to declare a global key like final textField1Key = GlobalKey<FormBuilderFieldState>(); and assign this key to your FormBuilderTextField. Before you call formKey.currentState!.save() you can now call formKey.currentState!.registerField('textField1', textField1Key.currentState!).
Edit
I had to add formKey.currentState!.setInternalFieldValue('textField1', textField1Key.currentState!.value, isSetState: true); instead of formKey.currentState!.registerField('textField1', textField1Key.currentState!) before save method. The register method just takes the initialValue and never updates it
This still an issue?
Yes17:25, 10 июня 2022 г., Matias de Andrea @.***>: This still an issue?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***> -- Отправлено из мобильного приложения Яндекс Почты
I don't understand why is this still a problem. I've being using dynamic fields with version 7.2.1 and 7.3.1 and didn't have problems with adding and removing fields on state change.
with unique names and correct deletion
Especially if they will have different names, I can't see it being a big problem. @tas-unn could you please explain a little bit more what was going wrong with the way you were trying?
@tas-unn please test the latest version of package and report if this issue still happend
@globalwebforce read our Code of Conduct. Your replay isn't accept in this organization because don't being respectful with one of our maintainers. If you continues, we will can restrict or ban access to this organization.
registerFieldandremoveInternalFieldValuefromformKeycurrentStatedoes not satisfy your situation?Author like you should be banned on Flutter, your answer is always the same on different questions, the worst thing is, it's non-sense, not useful and not testable, I hope this will be your last package.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.