Flutter Widget之DropdownButton

Widget:https://flutter.io/docs/development/ui/widgets
DropdownButton:https://docs.flutter.io/flutter/material/DropdownButton-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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import 'package:flutter/material.dart';

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

class _DropdownButtonDemoPageState extends State<DropdownButtonDemoPage> {
List<DropdownMenuItem> getListData() {
List<DropdownMenuItem> items = new List();
DropdownMenuItem dropdownMenuItem1 = new DropdownMenuItem(
child: new Text('中国'),
value: '1',
);
items.add(dropdownMenuItem1);
DropdownMenuItem dropdownMenuItem2 = new DropdownMenuItem(
child: new Text('美国'),
value: '2',
);
items.add(dropdownMenuItem2);
DropdownMenuItem dropdownMenuItem3 = new DropdownMenuItem(
child: new Text('俄罗斯'),
value: '3',
);
items.add(dropdownMenuItem3);
DropdownMenuItem dropdownMenuItem4 = new DropdownMenuItem(
child: new Text('日本'),
value: '4',
);
items.add(dropdownMenuItem4);
DropdownMenuItem dropdownMenuItem5 = new DropdownMenuItem(
child: new Text('德国'),
value: '5',
);
items.add(dropdownMenuItem5);
DropdownMenuItem dropdownMenuItem6 = new DropdownMenuItem(
child: new Text('英国'),
value: '6',
);
items.add(dropdownMenuItem6);
DropdownMenuItem dropdownMenuItem7 = new DropdownMenuItem(
child: new Text('法国'),
value: '7',
);
items.add(dropdownMenuItem7);
DropdownMenuItem dropdownMenuItem8 = new DropdownMenuItem(
child: new Text('意大利'),
value: '8',
);
items.add(dropdownMenuItem8);
DropdownMenuItem dropdownMenuItem9 = new DropdownMenuItem(
child: new Text('澳大利亚'),
value: '9',
);
items.add(dropdownMenuItem9);
DropdownMenuItem dropdownMenuItem10 = new DropdownMenuItem(
child: new Text('加拿大'),
value: '10',
);
items.add(dropdownMenuItem10);
return items;
}

var value;

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('DropdownButton Page Demo'),
),
body: new Column(
children: <Widget>[
new Center(
child: new DropdownButton(
items: getListData(),
hint: new Text('下拉选择你想要的数据'),
//当没有默认值的时候可以设置的提示
value: value,
//下拉菜单选择完之后显示给用户的值
onChanged: (T) {
//下拉菜单item点击之后的回调
setState(() {
value = T;
});
},
elevation: 24,
//设置阴影的高度
style: new TextStyle(
//设置文本框里面文字的样式
color: Colors.red
),
// isDense: false, //减少按钮的高度。默认情况下,此按钮的高度与其菜单项的高度相同。如果isDense为true,则按钮的高度减少约一半。 这个当按钮嵌入添加的容器中时,非常有用
iconSize: 50.0, //设置三角标icon的大小
),
),
],
),
);
}
}

Flutter Widget DropdownButton

Powered by AppBlog.CN     浙ICP备14037229号

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

访客数 : | 访问量 :