I\'ve recently started programming using dart and flutter and everything has been going smoothly for my app, although recently i wanted to add drop down menu to provide the user
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: [
new ListTile(
title: const Text('Frosting'),
trailing: new DropdownButton(
hint: Text('Choose'),
onChanged: (String changedValue) {
newValue=changedValue;
setState(() {
newValue;
print(newValue);
});
},
value: newValue,
items: ['None', 'Chocolate', 'Vanilla', 'ButterCream']
.map((String value) {
return new DropdownMenuItem(
value: value,
child: new Text(value),
);
}).toList()),
),
],
),
);
}