Skip to content

Commit 9c8866d

Browse files
committed
Merge branch 'lhr' into test
2 parents e1c0a92 + 6980c7f commit 9c8866d

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

docs/widget/form/checkbox/index.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
## **CheckBox**
1+
## **CheckBox**
2+
3+
>
4+
复选框
5+
* 复选框本身不保持任何状态
6+
* 当复选框的状态发生变化时,窗口小部件会调用onChanged回调
7+
* 大多数使用复选框的小部件将侦听onChanged回调并使用新值重建复选框以更新复选框的可视外观
8+
9+
### 构造方法
10+
``` dart
11+
Checkbox({
12+
Key key,
13+
@required this.value,
14+
this.tristate = false,
15+
@required this.onChanged,
16+
this.activeColor,
17+
this.materialTapTargetSize,
18+
})
19+
```
20+
21+
### 属性介绍
22+
* value: 复选框的状态
23+
* tristate: 当tristate为true,则复选框可以选择显示三个值 - true,false和null,当value为null时,将显示破折号。默认情况下, tristate为false,复选框的值必须为true或false
24+
* onChanged: 点击复选框的回调函数
25+
* activeColor: 选中此复选框时要使用的颜色
26+
* materialTapTargetSize: 配置点击目标的最小尺寸

lib/widget/form/checkbox/demo.dart

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,41 @@
11
import 'package:flutter/material.dart';
2+
import 'dart:math';
23

34
class Index extends StatefulWidget {
45
@override
56
_IndexState createState() => _IndexState();
67
}
78

89
class _IndexState extends State<Index> {
9-
bool _checkBoxValue = false;
10-
10+
List<bool> checkBoxValue = [false, true, true, false, true];
1111
@override
1212
Widget build(BuildContext context) {
13-
return ListView(
14-
children: <Widget>[
15-
Center(
16-
child: Checkbox(
17-
value: _checkBoxValue,
18-
onChanged: (value) {
19-
setState(() {
20-
_checkBoxValue = value;
21-
});
22-
},
23-
),
24-
)
25-
],
13+
return Scaffold(
14+
appBar: AppBar(title: Text('Checkbox'),),
15+
body: Center(
16+
child: Wrap(
17+
children: List.generate(5, (index) {
18+
Color color = _randomColor();
19+
return Checkbox(
20+
value: checkBoxValue[index],
21+
activeColor: color,
22+
tristate: false,
23+
onChanged: (value) {
24+
setState(() {
25+
checkBoxValue[index] = value;
26+
});
27+
},
28+
);
29+
}),
30+
),
31+
),
2632
);
2733
}
2834
}
2935

30-
31-
// class CheckBoxDemo extends StatefulWidget {
32-
// @override
33-
// _CheckBoxDemoState createState() => _CheckBoxDemoState();
34-
// }
35-
36-
// class _CheckBoxDemoState extends State<CheckBoxDemo> {
37-
// bool _checkBoxValue;
38-
// // _CheckBoxDemoState({Key key, this._checkBoxValue}):super(key: key);
39-
// @override
40-
// Widget build(BuildContext context) {
41-
// return Checkbox(
42-
// value: _checkBoxValue,
43-
// onChanged: (value) {
44-
// setState(() {
45-
// _checkBoxValue = value;
46-
// });
47-
// },
48-
// );
49-
// }
50-
// }
36+
Color _randomColor () {
37+
var red = Random.secure().nextInt(255);
38+
var green = Random.secure().nextInt(255);
39+
var blue = Random.secure().nextInt(255);
40+
return Color.fromARGB(255, red, green, blue);
41+
}

0 commit comments

Comments
 (0)