Flutter 开发之——Menu
const PopupMenuItem({
Key? key,
this.value,
this.enabled = true,
this.height = kMinInteractiveDimension,
this.textStyle,
this.mouseCursor,
required this.child,
})
3.2 属性说明
| 属性 | 说明 | 取值 |
| :-: | :-: | :-: |
| value | 当此项选中后,此值将会通过onSelected
返回 | T |
| enabled | 此项是否可用 | bool |
| height | 此项的高度 | double |
| textStyle | 文本样式 | TextStyle |
| child | 子控件 | Widget |
4.1 源码
const PopupMenuDivider({ Key? key, this.height = _kMenuDividerHeight })
4.2 属性说明
height:分割线控件的高度
5.1 源码
const CheckedPopupMenuItem({
Key? key,
T? value,
this.checked = false,
bool enabled = true,
Widget? child,
})
5.2 属性说明
| 属性 | 说明 | 取值 |
| :-: | :-: | :-: |
| value | 当此项选中后,此值将会通过onSelected
返回 | T |
| checked | 该控件是否被选中 | bool |
| enabled | 该控件是否可用 | bool |
| child | 子控件 | Widget |
6.1 PopupMenuButton+PopupMenuItem
代码
PopupMenuButton<String>(
shape: RoundedRectangleBorder(side: BorderSide(color: Colors.red), borderRadius: BorderRadius.circular(20)),
offset: Offset(0, 30),
elevation: 5,
padding: EdgeInsets.all(5),
//color: Colors.grey,
child: RaisedButton(child: Text('学科'),),
//icon: Icon(Icons.add),
initialValue: '语文',
tooltip: 'PopupMenuButton',
onSelected: (value) {
print('$value');
},
onCanceled: () {
print('onCanceled');
},
itemBuilder: (context) {
return <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: '语文',
child: Text('语文'),
),
PopupMenuDivider(height: 20,),
PopupMenuItem<String>(
value: '数学',
enabled: false,
child: Text('数学',style: TextStyle(color: Colors.red),),
),
PopupMenuDivider(),
PopupMenuItem<String>(
value: '英语',
child: Text('英语'),
),
PopupMenuDivider(),
PopupMenuItem<String>(
value: '生物',
child: Text('生物'),
),
PopupMenuDivider(),
PopupMenuItem<String>(
value: '化学',
child: Text('化学'),
),
];
},
)
效果图
6.2 PopupMenuButton+CheckedPopupMenuItem
代码
PopupMenuButton<String>(
onSelected: (value) {
print('$value');
},
itemBuilder: (context) {
return <PopupMenuEntry<String>>[
CheckedPopupMenuItem(
value: '语文',
checked: true,
child: Text('语文'),
),
CheckedPopupMenuItem(
value: '数学',
child: Text('数学'),
),
];
},
)
效果图
6.3 showMenu
代码
RaisedButton(child: Text("showMenu"),onPressed: () {
showMenu(
context: context,
评论