下拉弹出框PopupMenuButton

Posted by アライさん on 2020年11月12日
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
54
55
56
57
58
59
60
61
PopupMenuButton<String>(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
side: new BorderSide(
color: CommonColors.mainRed,
style: BorderStyle.solid,
)),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: ScreenUtil().setWidth(150),
),
child: Text(
_currTag,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(30),
),
),
),
Icon(
Icons.keyboard_arrow_down,
size: ScreenUtil().setWidth(40),
color: CommonColors.textGrey,
),
],
),
padding: EdgeInsets.zero,
itemBuilder: (BuildContext context) =>
_targetListWidget(context),
onSelected: (String value) {
setState(() {
_currTag = value;
});
}),


_targetListWidget(BuildContext context) {
List<PopupMenuItem<String>> targetList = [];
tags.forEach((element) {
targetList.add(PopupMenuItem<String>(
value: element,
child: Text(
element,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
fontSize: ScreenUtil().setSp(28),
),
),
));
});
return targetList;
}