0
点赞
收藏
分享

微信扫一扫

Flutter开发之——Menu,字节跳动Android三面凉凉

仲秋花似锦 2022-01-20 阅读 83

2.2 属性说明

| 属性 | 说明 | 取值 |

| :-: | :-: | :-: |

| initialValue | 初始值 | T |

| onSelected | 选中调用 | Function(T value) |

| onCanceled | 取消选中 | Function() |

| tooltip | 长按时显示文本 | String |

| child | menu控件 | Widget |

| icon | menu图标 | Widget |

| iconSize | 图标大小 | double |

| offset | 菜单弹出的位置 | Offset |

| shap
e | 弹出菜单边框 | ShapeBorder |

| color | 弹出菜单颜色 | Color |

三 PopupMenuItem


3.1 源码

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 |

四 PopupMenuDivider


4.1 源码

const PopupMenuDivider({ Key? key, this.height = _kMenuDividerHeight })

4.2 属性说明

  • height:分割线控件的高度

五 CheckedPopupMenuItem


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(

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>[

PopupMenuItem(

value: ‘语文’,

child: Text(‘语文’),

),

PopupMenuDivider(height: 20,),

PopupMenuItem(

value: ‘数学’,

enabled: false,

child: Text(‘数学’,style: TextStyle(color: Colors.red),),

),

PopupMenuDivider(),

PopupMenuItem(

value: ‘英语’,

child: Text(‘英语’),

),

PopupMenuDivider(),

PopupMenuItem(

value: ‘生物’,

child: Text(‘生物’),

),

PopupMenuDivider(),

PopupMenuItem(

value: ‘化学’,

child: Text(‘化学’),

),

];

},

)

PopupMenuItem(

value: ‘英语’,

child: Text(‘英语’),

),

PopupMenuDivider(),

PopupMenuItem(

value: ‘生物’,

child: Text(‘生物’),

),

PopupMenuDivider(),

PopupMenuItem(

value: ‘化学’,

child: Text(‘化学’),

),

];

},

)

举报

相关推荐

0 条评论