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?
- 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 yourStatefulWidget
. - 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 yourStatefulWidget
.
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
- Unable to locate android SDK flutter
- Flutter: Unhandled exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
- CocoaPods could not find compatible versions for pod “Firebase/CoreOnly”
- ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your flutter PATH. in flutter
- CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate in flutter
Thanks, you are the best
HelpFull you sloved my two days problem
Thank you bro.