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

[FormBuilderDropdown]: Not reverting to initial value upon form reset #1402

Open
2 of 7 tasks
kris175 opened this issue May 30, 2024 · 1 comment
Open
2 of 7 tasks
Labels
bug Something isn't working

Comments

@kris175
Copy link

kris175 commented May 30, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.3.0

Platforms

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

Flutter doctor

Flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] IntelliJ IDEA Community Edition (version 2023.2.2)
[✓] VS Code (version 1.89.1)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!

Minimal code example

Code sample
class MyForm extends StatefulWidget {
  const MyForm({super.key});

  @override
  _MyFormState createState() => _MyFormState();
}

class _MyFormState extends State<MyForm> {
  final _formKey = GlobalKey<FormBuilderState>();

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: FormBuilder(
        key: _formKey,
        child: Column(
          children: <Widget>[
            FormBuilderDropdown(
              name: 'dropdown',
              decoration: const InputDecoration(
                labelText: 'Select Option',
              ),
              // hint: Text('Select Option'), // Optional
              items: const [
                DropdownMenuItem(
                  value: 'Option 1',
                  child: Text('Option 1'),
                ),
                DropdownMenuItem(
                  value: 'Option 2',
                  child: Text('Option 2'),
                ),
                DropdownMenuItem(
                  value: 'Option 3',
                  child: Text('Option 3'),
                ),
              ],
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                print("BEFORE RESET");
                print(_formKey.currentState?.value);
                _formKey.currentState?.reset();
                print("AFTER RESET");
                print(_formKey.currentState?.value);
              },
              child: const Text('Reset'),
            ),
          ],
        ),
      ),
    );
  }
}

Current Behavior

The dropdown field is not reverting to the initial value upon form reset. It instead retains the value that has been selected prior to reset.

Expected Behavior

Dropdown field should be reset to initial value when the form is reset

Steps To Reproduce

  1. Run app
  2. Dropdown field has initial value as null. Select an option
  3. Press reset button

Aditional information

flutter: BEFORE RESET
flutter: {dropdown: Option 2}
flutter: AFTER RESET
flutter: {dropdown: Option 2}
@kris175 kris175 added the bug Something isn't working label May 30, 2024
@kris175
Copy link
Author

kris175 commented May 31, 2024

Could be related to this issue - #1389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
1 participant