Skip to content

Commit b04150a

Browse files
committed
代码优化
1 parent 6e2455e commit b04150a

File tree

1 file changed

+22
-66
lines changed

1 file changed

+22
-66
lines changed

lib/widget/regular/row/demo.dart

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ class _IndexState extends State<Index> {
1414
MainAxisAlignment.spaceBetween,
1515
MainAxisAlignment.spaceEvenly
1616
];
17+
List mainValue1 = ['start', 'center', 'end'];
18+
List mainValue2 = ['Around', 'Between', 'Evenly'];
1719
int mainAxisAlignmentIndex = 0;
20+
1821
List crossAxisAlignment = [
1922
CrossAxisAlignment.start,
2023
CrossAxisAlignment.center,
2124
CrossAxisAlignment.end
2225
];
26+
List crossValue1 = ['start', 'center', 'end'];
2327
int crossAxisAlignmentIndex = 0;
2428

2529
@override
@@ -35,91 +39,43 @@ class _IndexState extends State<Index> {
3539
child: Text('修改mainAxisAligment的值'),
3640
),
3741
Row(
38-
children: <Widget>[
39-
FlatButton(
40-
child: Text('start'),
41-
onPressed: (){
42-
setState(() {
43-
mainAxisAlignmentIndex = 0;
44-
});
45-
},
46-
),
47-
FlatButton(
48-
child: Text('center'),
49-
onPressed: (){
50-
setState(() {
51-
mainAxisAlignmentIndex = 1;
52-
});
53-
},
54-
),
55-
FlatButton(
56-
child: Text('end'),
42+
children: List.generate(3, (index) {
43+
return FlatButton(
44+
child: Text('${mainValue1[index]}'),
5745
onPressed: (){
5846
setState(() {
59-
mainAxisAlignmentIndex = 2;
47+
mainAxisAlignmentIndex = index;
6048
});
6149
},
62-
)
63-
],
50+
);
51+
})
6452
),
6553
Row(
66-
children: <Widget>[
67-
FlatButton(
68-
child: Text('Around'),
69-
onPressed: (){
70-
setState(() {
71-
mainAxisAlignmentIndex = 3;
72-
});
73-
},
74-
),
75-
FlatButton(
76-
child: Text('Between'),
54+
children: List.generate(3, (index) {
55+
return FlatButton(
56+
child: Text('${mainValue2[index]}'),
7757
onPressed: (){
7858
setState(() {
79-
mainAxisAlignmentIndex = 4;
59+
mainAxisAlignmentIndex = index + 3;
8060
});
8161
},
82-
),
83-
FlatButton(
84-
child: Text('Evenly'),
85-
onPressed: (){
86-
setState(() {
87-
mainAxisAlignmentIndex = 5;
88-
});
89-
},
90-
),
91-
],
62+
);
63+
})
9264
),
9365
SizedBox(
9466
child: Text('修改crossAxisAlignment的值')
9567
),
9668
Row(
97-
children: <Widget>[
98-
FlatButton(
99-
child: Text('start'),
69+
children: List.generate(3, (index) {
70+
return FlatButton(
71+
child: Text('${crossValue1[index]}'),
10072
onPressed: (){
10173
setState(() {
102-
crossAxisAlignmentIndex = 0;
74+
crossAxisAlignmentIndex = index;
10375
});
10476
},
105-
),
106-
FlatButton(
107-
child: Text('center'),
108-
onPressed: (){
109-
setState(() {
110-
crossAxisAlignmentIndex = 1;
111-
});
112-
},
113-
),
114-
FlatButton(
115-
child: Text('end'),
116-
onPressed: (){
117-
setState(() {
118-
crossAxisAlignmentIndex = 2;
119-
});
120-
},
121-
),
122-
],
77+
);
78+
})
12379
),
12480
Row(
12581
mainAxisAlignment: mainAxisAlignment[mainAxisAlignmentIndex],

0 commit comments

Comments
 (0)