[Solved] Drop down button in flutter not switching values to the selected value

Hello Guys How are you all? Hope You all are fine. Drop down button in flutter not switching values to the selected value in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How to Solve Drop down button in flutter not switching values to the selected value?

  1. How to Solve Drop down button in flutter not switching values to the selected value?

    The error is because you are declaring a method variable newValue. To Solve Drop down button in flutter not switching values to the selected value you must declare that variable as global inside your StatefulWidget.

  2. Drop down button in flutter not switching values to the selected value

    The error is because you are declaring a method variable newValue. To Solve Drop down button in flutter not switching values to the selected value you must declare that variable as global inside your StatefulWidget.

Solution 1

The error is because you are declaring a method variable newValue you must declare that variable as global inside your StatefulWidget.

String newValue;

Widget buildDropdownButton() {
  return new Padding(
    padding: const EdgeInsets.all(24.0),
    child: new Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        new ListTile(
          title: const Text('Frosting'),
          trailing: new DropdownButton<String>(
              hint: Text('Choose'),
              onChanged: (String changedValue) {
                newValue=changedValue;
                setState(() {
                  newValue;
                  print(newValue);
                });
              },
              value: newValue,
              items: <String>['None', 'Chocolate', 'Vanilla', 'ButterCream']
                  .map((String value) {
                return new DropdownMenuItem<String>(
                  value: value,
                  child: new Text(value),
                );
              }).toList()),
        ),
      ],
    ),
  );
}

Solution 2

Just Change DropdownButton to DropdownButtonFormField and add onSaved exactly as onChanged:

onSaved: (value) {
    setState(() {
        _selectedValue = value;
    });
}

That’s it. It will start working.

Summery

So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

3 thoughts on “[Solved] Drop down button in flutter not switching values to the selected value”

Leave a Comment

  Canva Pro Crack Filmora Pro Crack Spotify Premium Free Download Tradingview Premium Free