Skip to content

Unable to set initial value to DropdownButtonFieldForm [1.17.0] #56716

Closed

Description

@arnold-parge

Steps to Reproduce

  1. Assign a default value in value for DropdownButtonFormField.

Expected results: The dropdown should show the value

Actual results: dropdown is showing blank value

Note:

  • I am facing this after upgrading to 1.17.0. My previous version was 1.12.13.
  • On 1.17.0, DropdownButton works fine but DropdownButtonFormField doesn't

Flutter Doctor:

[✓] Flutter (Channel stable, v1.17.0, on Linux, locale en_IN)
    • Flutter version 1.17.0 at /home/arnold/flutter
    • Framework revision e6b34c2b5c (6 days ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/arnold/Android/Sdk
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /home/arnold/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b16-5323222)
    • All Android licenses accepted.

[!] Android Studio (version 3.4)
    • Android Studio at /home/arnold/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b16-5323222)

[✓] VS Code (version 1.43.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.9.1

[✓] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

! Doctor found issues in 1 category.

Activity

  1. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: regressionIt was better in the past than it is now
    on May 8, 2020
  2. shihaohong commented on May 11, 2020

    @shihaohong
    Contributor

    Hi @arnold-parge, could you please share a minimal reproducible sample? I tried the following simple app and it seems to work just fine on the master and stable branches:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: MyHomePage(title: 'Test DropdownButtonFormField'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      String dropdownValue = 'two';
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Form(
                  child: DropdownButtonFormField<String>(
                    value: dropdownValue,
                    onChanged: (String newValue) {
                      setState(() {dropdownValue = newValue;});
                    },
                    items: [
                      DropdownMenuItem(
                        child: Text('option one'),
                        value: 'one',
                      ),
                      DropdownMenuItem(
                        child: Text('option two'),
                        value: 'two',
                      ),
                      DropdownMenuItem(
                        child: Text('option three'),
                        value: 'three',
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
  3. github-actions commented on Aug 21, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Aug 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: regressionIt was better in the past than it is nowframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packageswaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions