Flutter Widget之PopupMenuButton

Widget:https://flutter.io/docs/development/ui/widgets
PopupMenuButton:https://docs.flutter.io/flutter/material/PopupMenuButton-class.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'package:flutter/material.dart';

class PopupMenuButtonDemoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _PopupMenuButtonDemoPageState();
}

enum WhyFarther { harder, smarter, selfStarter, tradingCharter }

class _PopupMenuButtonDemoPageState extends State<PopupMenuButtonDemoPage> {
WhyFarther _selection;

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('PopupMenuButton Page Demo'),
),
body: new Column(
children: <Widget>[
new Center(
child: new PopupMenuButton<WhyFarther>(
onSelected: (WhyFarther result) {
setState(() {
_selection = result;
print(result);
});
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<WhyFarther>>[
const PopupMenuItem<WhyFarther>(
value: WhyFarther.harder,
child: Text('Working a lot harder'),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.smarter,
child: Text('Being a lot smarter'),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.selfStarter,
child: Text('Being a self-starter'),
),
const PopupMenuItem<WhyFarther>(
value: WhyFarther.tradingCharter,
child: Text('Placed in charge of trading charter'),
),
],
)
),
],
),
);
}
}

Flutter Widget PopupMenuButton

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :