-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchAndCheckBoxAbout.dart
71 lines (65 loc) · 1.72 KB
/
SwitchAndCheckBoxAbout.dart
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
import 'package:flutter/material.dart';
import 'package:flutter_starter_notes/component/CommonTitle.dart';
class SwitchAndCheckBoxAbout extends StatelessWidget {
SwitchAndCheckBoxAbout({Key key, this.title});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
CommonTitle('Switch 和 Checkbox 示例'),
Container(
padding: EdgeInsets.all(10),
child: SwitchAndCheckBoxTestRoute(),
)
],
),
),
);
}
}
class SwitchAndCheckBoxTestRoute extends StatefulWidget {
@override
_SwitchAndCheckBoxTestRouteState createState() =>
new _SwitchAndCheckBoxTestRouteState();
}
class _SwitchAndCheckBoxTestRouteState
extends State<SwitchAndCheckBoxTestRoute> {
bool _selected = true;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Switch(
value: _selected, //当前状态
onChanged: (value) {
print('Switch' + value.toString());
//重新构建页面
setState(() {
_selected = value;
});
},
),
Checkbox(
value: _selected,
activeColor: Colors.red, //选中时的颜色
onChanged: (value) {
print('Checkbox' + value.toString());
setState(() {
_selected = value;
});
},
),
Container(
padding: EdgeInsets.all(10),
child: Text(_selected ? "打开" : "关闭"),
)
],
);
}
}