Flutter Widget之Checkbox

Widget:https://flutter.io/docs/development/ui/widgets
Checkbox:https://docs.flutter.io/flutter/material/Checkbox-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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import 'package:flutter/material.dart';

class CheckBoxDemoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _CheckBoxDemoPageState();
}
}

class _CheckBoxDemoPageState extends State<CheckBoxDemoPage> {
bool isCheck = false;
List<bool> isChecks = [false, false];

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text('CheckBox Demo'),
),
body: new Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Center(
child: new Checkbox(
value: isCheck,
activeColor: Colors.red,
onChanged: (bool) {
setState(() {
isCheck = bool;
});
},
),
),
new Center(
child: new CheckboxListTile(
value: isCheck,
title: new Text('Joe.Ye'),
controlAffinity: ListTileControlAffinity.platform,
//控制亲和度: leading按钮显示在文字前面, trailing按钮显示在文字的后面, platform显示样式根据手机当前平台默认显示
onChanged: (bool) {
setState(() {
isCheck = bool;
});
}),
),
new Center(
child: new CheckboxListTile(
value: isCheck,
title: new Text('Joe.Ye'),
secondary: const Icon(Icons.access_alarm),
controlAffinity: ListTileControlAffinity.platform,
onChanged: (bool) {
setState(() {
isCheck = bool;
});
}),
),
new Center(
child: new CheckboxListTile(
value: isCheck,
title: new Text('Joe.Ye'),
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool) {
setState(() {
isCheck = bool;
});
}),
),
new Center(
child: new CheckboxListTile(
value: isCheck,
title: new Text('AppBlog.CN'),
controlAffinity: ListTileControlAffinity.trailing,
onChanged: (bool) {
setState(() {
isCheck = bool;
});
}),
),
new Center(
child: new CheckboxListTile(
value: isCheck,
title: new Text('http://www.appblog.cn'),
controlAffinity: ListTileControlAffinity.platform,
onChanged: (bool) {
setState(() {
isCheck = bool;
});
}),
),
new Center(
child: new CheckboxListTile(
value: isChecks[0],
title: new Text('Android'),
controlAffinity: ListTileControlAffinity.platform,
onChanged: (bool) {
setState(() {
isChecks[0] = bool;
});
}),
),
new Center(
child: new CheckboxListTile(
value: isChecks[1],
title: new Text('iOS'),
controlAffinity: ListTileControlAffinity.platform,
onChanged: (bool) {
setState(() {
isChecks[1] = bool;
});
}),
)
],
)
);
}
}

Flutter Widget Checkbox

Powered by AppBlog.CN     浙ICP备14037229号

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

访客数 : | 访问量 :