Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class SelectColor extends StatefulWidget {
@override
_SelectColorState createState() => _SelectColorState();
}
class _SelectColorState extends State<SelectColor> {
final List<String> _colors = ['Red', 'Green', 'Blue'];
String _selectedColor;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
DropdownButton(
value: _selectedColor,
items: _colors.map((String color) {
return DropdownMenuItem(
value: color,
child: Text(color),
);
}).toList(),
onChanged: (value) {
setState(() {
_selectedColor = value;
});
},
),
Text('Selected: ${_selectedColor ?? "}'),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.