Skip to content

FormBuilderDropdown onChanged fires twice during form Reset #1371

@Adam-Langley

Description

@Adam-Langley

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.2.1

Platforms

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

Flutter doctor

Flutter doctor

Minimal code example

Code sample
FormBuilder(
    child: Column(
      children: [
        Builder(
          builder: (context) {
            return ElevatedButton(onPressed: (){
              FormBuilder.of(context)!.reset();
            }, child: Text('reset'));
          }
        ),
        FormBuilderDropdown(
          name: 'test', 
          initialValue: 'A', 
          items: [
            DropdownMenuItem(child: Text('A'), value: 'A'),
            DropdownMenuItem(child: Text('B'), value: 'B')
          ],
          onChanged: (value) {
            print('Changed value to $value');
          },
        ),
      ],
    ),
  ),

Current Behavior

When resetting the form, the dropdowns "onChange" handler will fire twice in quick succession - one setting it to the "initialValue", then a second setting it back to the value it was before the reset button was clicked (essentially undoing the reset).

Expected Behavior

When resetting the form, the "onChange" should fire only once, and the passed value should be the "initialValue".

Steps To Reproduce

Using the above code snippet.

  1. Run the code
  2. Click the dropdown and change its value to "B"
  3. Press the "reset" button

Note that it will not reset, but stay as "B", and the debug console will read

flutter: Changed value to A
flutter: Changed value to B

Aditional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions