Drop down button in flutter not switching values to the selected value. The error is because you are declaring a method variable newValue you must declare that variable as global inside your StatefulWidget.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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()), ), ], ), ); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.