Skip to content

Instantly share code, notes, and snippets.

@manofi21
Created August 31, 2019 04:00
Show Gist options
  • Save manofi21/867fc4a5af96f1be88c3e4f14d7f1475 to your computer and use it in GitHub Desktop.
Save manofi21/867fc4a5af96f1be88c3e4f14d7f1475 to your computer and use it in GitHub Desktop.
how to show dropdownbutton in flutter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static List<String> menuItems = <String>[
'One',
'Two',
'Three',
'Four',
];
final List<DropdownMenuItem<String>> _dropDownMenuItems = menuItems
.map(
(String value) => DropdownMenuItem<String>(
value: value,
child: Text(value),
),
)
.toList();
String _btn1SelectedVal = 'One';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ListView(
children: <Widget>[
ListTile(
title: Text('DropDownButton with default:'),
trailing: DropdownButton<String>(
// Must be one of items.value.
value: _btn1SelectedVal,
onChanged: (String newValue) {
setState(() {
_btn1SelectedVal = newValue;
});
},
items: this._dropDownMenuItems,
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment