DropDownButton可以实现一个下拉框效果的按钮。
int selectedValue = 1;
@override
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'),
DropdownButton(
value: selectedValue,
items: const [
DropdownMenuItem(
child: Text('A'),
value: 1,
),
DropdownMenuItem(
child: Text('B'),
value: 2,
),
DropdownMenuItem(
child: Text('C'),
value: 3,
)
],
onChanged: (newValue){
setState((){
selectedValue = newValue as int;
});
}
)
],
),
),
);
}