Skip to content

Instantly share code, notes, and snippets.

@abdyer
Created April 5, 2018 09:25
Show Gist options
  • Save abdyer/a559718e9bfb2779402604121070f2f8 to your computer and use it in GitHub Desktop.
Save abdyer/a559718e9bfb2779402604121070f2f8 to your computer and use it in GitHub Desktop.
Flutter DropdownButton Example
class _DropdownButtonBugState extends State<DropdownButtonBug> {
final List<String> _items = ['One', 'Two', 'Three', 'Four'].toList();
String _selection;
@override
void initState() {
_selection = _items.first;
super.initState();
}
@override
Widget build(BuildContext context) {
final dropdownMenuOptions = _items
.map((String item) =>
new DropdownMenuItem<String>(value: item, child: new Text(item))
)
.toList();
return new Scaffold(
body: new DropdownButton<String>(
value: _selection,
items: dropdownMenuOptions,
onChanged: (s) {
setState(() {
_selection = s;
});
}
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment