flutter控件之弹出菜单PopupmenuButton控件PopupMenuButton控件即弹出菜单控件,点击控件会出现菜单。
import 'package:flutter/material.dart';
class MenusDemo extends StatefulWidget{
@override
_MenusDemoState createState() => new _MenusDemoState();
}
class _MenusDemoState extends State<MenusDemo>{
flutter开发appString _bodyStr = "显⽰菜单内容";
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("弹出菜单控件"),
actions: <Widget>[
new PopupMenuButton(
onSelected: (String value){
setState(() {
_bodyStr = value;
});
},
itemBuilder: (BuildContext context) =><PopupMenuItem<String>>[
new PopupMenuItem(
value:"选项⼀的内容",
child: new Text("选项⼀")
),
new PopupMenuItem(
value: "选项⼆的内容",
child: new Text("选项⼆")
)
]
)
],
),
body: new Center(
child: new Text(_bodyStr),
),
);
}
}
void main(){
runApp(new MaterialApp(
title: "弹出菜单控件",
theme: new ThemeData(primaryColor: Colors.deepOrange),
home: new MenusDemo(),
)
);
}
效果:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论