flutter_form_builder icon indicating copy to clipboard operation
flutter_form_builder copied to clipboard

dynamically add/remove widget with form_builder fields

Open tas-unn opened this issue 3 years ago • 6 comments
trafficstars

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

  1. in _PersonalState i create list widget static List<Widget> ws=List.empty(growable: true); int _numparents=0;

  2. 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("+"))

tas-unn avatar Nov 30 '21 12:11 tas-unn

registerField and removeInternalFieldValue from formKey currentState does not satisfy your situation?

WilliamCunhaCardoso avatar Feb 23 '22 15:02 WilliamCunhaCardoso

registerField and removeInternalFieldValue from formKey currentState does 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.

globalwebforce avatar Apr 29 '22 07:04 globalwebforce

registerField and removeInternalFieldValue from formKey currentState does 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

phantomate avatar Apr 30 '22 11:04 phantomate

This still an issue?

deandreamatias avatar Jun 10 '22 14:06 deandreamatias

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: @.***> -- Отправлено из мобильного приложения Яндекс Почты

tas-unn avatar Jun 10 '22 14:06 tas-unn

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?

CaLouro avatar Jun 27 '22 00:06 CaLouro

@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.

registerField and removeInternalFieldValue from formKey currentState does 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.

deandreamatias avatar Aug 19 '22 08:08 deandreamatias

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.

github-actions[bot] avatar Sep 19 '22 02:09 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Sep 27 '22 02:09 github-actions[bot]