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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
import 'package:flutter/material.dart';
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
class ConstraintLayoutPage extends StatefulWidget {
const ConstraintLayoutPage({Key? key}) : super(key: key);
@override
State<ConstraintLayoutPage> createState() => _ConstraintLayoutPageState();
}
class _ConstraintLayoutPageState extends State<ConstraintLayoutPage> {
final ConstraintId appLogoId = ConstraintId('appLogoId');
final ConstraintId appTitleId = ConstraintId('appTitleId');
final ConstraintId appAccountId = ConstraintId('appAccountId');
final ConstraintId passwordId = ConstraintId('passwordId');
final ConstraintId loginId = ConstraintId('loginId');
final ConstraintId registId = ConstraintId('registId');
final ConstraintId otherId = ConstraintId('otherId');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ConstraintLayout'),
),
body: ConstraintLayout(
children: <Widget>[
_buildAppLogo(),
_buildAppTitle(),
_buildInputContainer(
id: appAccountId,
topConstraint: appTitleId.bottom.margin(40),
hintText: '请输入账户名',
icon: Icons.person,
),
_buildInputContainer(
id: passwordId,
topConstraint: appAccountId.bottom.margin(20),
hintText: '请输入密码',
icon: Icons.password,
),
_buildElevatedButton(
id: loginId,
topConstraint: passwordId.bottom.margin(70),
buttonText: '登陆',
backgroundColor: const Color(0xff5B70CF),
),
_buildElevatedButton(
id: registId,
topConstraint: loginId.bottom.margin(30),
buttonText: '注册',
backgroundColor: const Color(0xffF8644E),
),
_buildTextWithConstraints(
id: otherId,
text: '其他方式登录',
topConstraint: registId.bottom.margin(60),
centerHorizontalTo: parent,
),
_buildSocialLoginRow(),
],
),
);
// // AppBar
}
// 构建logo
Widget _buildAppLogo() {
return Image.asset(
'assets/images/login/app_logo.png',
width: 120,
).applyConstraint(
top: parent.top.margin(60),
left: parent.left.margin(20),
right: parent.right.margin(20),
id: appLogoId,
);
}
// 构建app的名称
Widget _buildAppTitle() {
return const Text(
"APP Name",
style: TextStyle(fontSize: 20, color: Color(0xFFBECEFA)),
).applyConstraint(
id: appTitleId,
top: appLogoId.bottom.margin(10),
left: parent.left,
right: parent.right,
);
}
// 构建输入框:账号/密码
Widget _buildInputContainer({
required ConstraintId id,
required ConstraintAlign topConstraint,
required String hintText,
required IconData icon,
}) {
return Container(
color: const Color(0xFFF0F5FD),
child: Row(
children: [
const SizedBox(width: 10),
Icon(icon),
const SizedBox(width: 20),
Expanded(
child: TextField(
style: const TextStyle(
color: Color(0xffA0ACD4),
fontSize: 20,
),
decoration: InputDecoration(
border: InputBorder.none,
hintText: hintText,
hintStyle: const TextStyle(color: Color(0xffA0ACD4)),
labelStyle: const TextStyle(color: Color(0xffA0ACD4)),
),
),
),
],
),
).applyConstraint(
id: id,
width: matchConstraint,
height: 60,
top: topConstraint,
left: parent.left.margin(20),
right: parent.right.margin(20),
);
}
// 构建登陆/注册
Widget _buildElevatedButton({
required ConstraintId id,
required ConstraintAlign topConstraint,
required String buttonText,
required Color backgroundColor,
}) {
return ElevatedButton(
onPressed: () {
debugPrint('点击了按钮:$buttonText');
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(backgroundColor),
),
child: Text(
buttonText,
style: const TextStyle(
fontSize: 20,
color: Colors.white,
),
),
).applyConstraint(
id: id,
top: topConstraint,
width: matchConstraint,
height: 60,
left: parent.left.margin(120),
right: parent.right.margin(120),
);
}
// 构造说明文本
Widget _buildTextWithConstraints({
required ConstraintId id,
required String text,
required ConstraintAlign topConstraint,
required ConstraintId centerHorizontalTo,
}) {
return Text(
text,
style: const TextStyle(
fontSize: 16,
color: Color(0xFFD5DFF2),
),
).applyConstraint(
id: id,
left: parent.left,
right: parent.right,
top: topConstraint,
centerHorizontalTo: centerHorizontalTo,
);
}
// 构建其它登录方式:微信,QQ,微博
Widget _buildSocialLoginRow() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
debugPrint('点击了微信登录');
},
child: Image.asset(
'assets/images/login/wechat.png',
width: 40,
height: 40,
),
),
const SizedBox(width: 20),
InkWell(
onTap: () {
debugPrint('点击了QQ登录');
},
child: Image.asset(
'assets/images/login/qq.png',
width: 40,
height: 40,
),
),
const SizedBox(width: 20),
InkWell(
onTap: () {
debugPrint('点击了微博登录');
},
child: Image.asset(
'assets/images/login/weibo.png',
width: 40,
height: 40,
),
),
],
).applyConstraint(
width: matchParent,
top: otherId.bottom.margin(20),
);
}
}
|