PopupMenuButton可以实现,点击按钮后,弹出选项的一个效果。
List<String> popupMenuItems = ['A', 'B', 'C'];
String selectedValue = 'A';
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('title'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('You have pushed this button many times'),
Text('test2'),
PopupMenuButton(
icon: Icon(Icons.add),
initialValue: selectedValue,
onSeletcted: (String newValue){
setState((){
selectedValue = newValue;
});
},
itemBuilder: (context){
return popupMenuItems.map((e) => PopupMenuItem(
child: Text(e), value: e,)
).toList();
}
),
Text(selectedValue);
],
),
),
);
}