Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse same widget causes child form field to be overwritten #1365

Open
4 of 7 tasks
Adam-Langley opened this issue Feb 13, 2024 · 0 comments
Open
4 of 7 tasks

Reuse same widget causes child form field to be overwritten #1365

Adam-Langley opened this issue Feb 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Adam-Langley
Copy link

Adam-Langley commented Feb 13, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.1.1

Platforms

  • Android
  • iOS
  • Linux
  • MacOS
  • Web
  • Windows

Flutter doctor

Flutter doctor

Minimal code example

Code sample (pseudocode)
class ChildWidget
{
   ChildWidget(this.name)

   build() => FormBuilderDropdown(name: '${this.name}_dropdown');
}

class MainWidget
{
  build() => FormBuilder(child: Column(children: [ChildWidget(name: "a"), ChildWidget(name: "b")]));
}

Current Behavior

When the FormBuilder.onChanged fires, the FormBuilderState.fields collection contains ONLY the field "b_dropdown" (the last childwidget to build).

A runtime warning is output "flutter: Warning! Replacing duplicate Field for a_dropdown -- this is OK to ignore as long as the field was intentionally replaced"

Expected Behavior

When the FormBuilder.onChanged fires, the FormBuilderState.fields collection should contain BOTH the fields "a_dropdown" and "b_dropdown".

Steps To Reproduce

On any environment, create a widget tree where a child widget (in my example I've called the class ChildWidget) is used multiple times in the same form.
The child widget should contain a FormBuilder form field, but it uses some unique name (i.e passed by argument) to name the field.

It appears that the FormBuilder subsystem is perhaps using the widget tree to identify form fields, because the last ChildWidget to render will have its formfields added to the FormBuilder.fields collection, overwriting the previous ones.

Aditional information

No response

@Adam-Langley Adam-Langley added the bug Something isn't working label Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant