/
Day2.dart
196 lines (182 loc) · 6.32 KB
/
Day2.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* Day 2
* Button
*/
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'dart:core';
class Day2 extends StatefulWidget {
@override
createState() => Day2State();
}
class Day2State extends State<Day2> {
var mCurrentValue = 1.0;
var isChecked=false;
int groupValue1,groupValue2;
@override
Widget build(BuildContext context) {
Widget buttonSection = Container(
padding: const EdgeInsets.all(15.0),
color: Colors.white,
child: Column(
children: [
// RaisedButton
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
child: new RaisedButton(
onPressed: () {print('button click');},
child: new Text("RaisedButton"),
),
),
// FlatButton
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
child: new FlatButton(
onPressed: () {print('button click');},
child: new Text("FlatButton"),
color: Color(0xFFe16552),
),
),
//FloatingActionButton 多个FloatingActionButton的时候会报错,要加 heroTag: null
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
// FloatingActionButton
new FloatingActionButton(
onPressed: () {print('button click');},
foregroundColor: Colors.white,
backgroundColor: Color(0xFFf19670),
child: new Icon(Icons.add),
heroTag: null,
),
// FloatingActionButton
new FloatingActionButton(
onPressed: () {print('button click');},
foregroundColor: Colors.white,
backgroundColor: Color(0xFFf19670),
child: new Text("文字"),
heroTag: null,
),
],
),
),
// FloatingActionButton.extended
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
child: new FloatingActionButton.extended(
onPressed: () {
print('button click');
},
foregroundColor: Colors.white,
backgroundColor: Colors.amber,
icon: new Icon(Icons.flag,color: Colors.red,),
label: new Text('FloatingActionButton.extended', maxLines: 1),
)
),
// Slider
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
child: new Slider(
value: mCurrentValue,
min: 1.0,
max: 10.0,
onChanged: (e) {
setState(() {
//四舍五入的双精度值
mCurrentValue = e.roundToDouble();
});
}
)
),
// Checkbox
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
child: new Checkbox(
value: isChecked,
onChanged: (bool){
setState(() {
isChecked=bool;
});
}, activeColor: Colors.blue,
)
),
// Radio
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
child: new ButtonBar(//ButtonBar:水平排列按钮
alignment: MainAxisAlignment.center,
children: <Widget>[
//value和groupValue值一样的话,则按钮选中
new Radio(value: 1,
groupValue: groupValue1,
onChanged: (int e) => updateGroupValue(e)),
new Radio(value: 2,
groupValue: groupValue1,
onChanged: (int e) => updateGroupValue(e)),
new Radio(value: 3,
groupValue: groupValue1,
onChanged: (int e) => updateGroupValue(e)),
new Radio(value: 4,
groupValue: groupValue1,
onChanged: (int e) => updateGroupValue(e)),
//value 值为 null 则表示按钮不可用
new Radio(value: null, groupValue: null, onChanged: null)
],
)
),
// Radio
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 0.0),
child: new Column(//ButtonBar:水平排列按钮
children: <Widget>[
//value和groupValue值一样的话,则按钮选中
new RadioListTile<int>(
title: const Text('A'),
value: 1,
activeColor: Colors.red,
groupValue: groupValue2,
onChanged: (int e)=>updateGroupValue2(e),
),
new RadioListTile<int>(
title: const Text('B'),
value: 2,
activeColor: Colors.yellow,
groupValue: groupValue2,
onChanged: (int e)=>updateGroupValue2(e),
),
new RadioListTile<int>(
title: const Text('C'),
value: 3,
activeColor: Colors.green,
groupValue: groupValue2,
onChanged: (int e)=>updateGroupValue2(e),
),
],
)
),
],
),
);
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: CupertinoNavigationBar(
middle: Text('Button'),
),
body: buttonSection,
);
}
///更新 groupValue1, 当Radio的value==groupValue 时候,则按钮被选中
void updateGroupValue(int e){
setState(() {
groupValue1=e;
});
}
///更新 groupValue2, 当Radio的value==groupValue 时候,则按钮被选中
void updateGroupValue2(int e){
setState(() {
groupValue2=e;
});
}
}