Skip to content

Commit 3a3cbec

Browse files
committed
feat: add initial implementation of SMS code input
1 parent 9160874 commit 3a3cbec

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/logic/network/network_repo.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class NetworkRepo {
164164
String account,
165165
String pwd,
166166
String captcha,
167+
String code,
167168
) async {
168169
return Request().post(Api.onLogin,
169170
data: FormData.fromMap({
@@ -173,7 +174,7 @@ class NetworkRepo {
173174
'login': account,
174175
'password': pwd,
175176
'captcha': captcha,
176-
'code': '',
177+
'code': code,
177178
}),
178179
options: Options(contentType: Headers.formUrlEncodedContentType));
179180
}

lib/pages/login/login_page.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ class _LoginPageState extends State<LoginPage> {
3434
final TextEditingController _accountController = TextEditingController();
3535
final TextEditingController _pwdController = TextEditingController();
3636
final TextEditingController _captchaController = TextEditingController();
37+
final TextEditingController _smsCodeController = TextEditingController();
3738
final FocusNode _pwdFocusNode = FocusNode();
3839
final FocusNode _captchaFocusNode = FocusNode();
3940
String? _requestHash;
4041
bool _showCaptcha = false;
42+
bool _showSmsCodeInput = false;
4143
final _captchaImg = StreamController<Uint8List?>();
4244

4345
String urlPreGetParam = '/auth/login?type=mobile';
@@ -90,7 +92,8 @@ class _LoginPageState extends State<LoginPage> {
9092
_requestHash!,
9193
_accountController.text,
9294
_pwdController.text,
93-
_captchaController.text);
95+
_captchaController.text,
96+
_smsCodeController.text);
9497
LoginResponse loginResponse =
9598
LoginResponse.fromJson(jsonDecode(response.data));
9699
if (loginResponse.status == 1) {
@@ -112,9 +115,12 @@ class _LoginPageState extends State<LoginPage> {
112115
if (!loginResponse.message.isNullOrEmpty) {
113116
SmartDialog.showToast(loginResponse.message!);
114117
}
118+
115119
if (loginResponse.message == '图形验证码不能为空", "图形验证码错误' ||
116120
(_showCaptcha && loginResponse.message == '密码错误')) {
117121
_onGetCaptcha();
122+
} else if (loginResponse.message == '请输入短信验证码') {
123+
_showSmsCodeInput = true;
118124
}
119125
}
120126
} catch (e) {
@@ -166,6 +172,7 @@ class _LoginPageState extends State<LoginPage> {
166172
_accountController.dispose();
167173
_pwdController.dispose();
168174
_captchaController.dispose();
175+
_smsCodeController.dispose();
169176
_pwdFocusNode.dispose();
170177
_captchaFocusNode.dispose();
171178
super.dispose();
@@ -328,6 +335,27 @@ class _LoginPageState extends State<LoginPage> {
328335
: const SizedBox.shrink(),
329336
),
330337
const SizedBox(height: 20),
338+
Visibility(
339+
visible: _showSmsCodeInput,
340+
child: SizedBox(
341+
width: 500.0,
342+
child: TextField(
343+
controller: _smsCodeController,
344+
inputFormatters: [
345+
LengthLimitingTextInputFormatter(6),
346+
FilteringTextInputFormatter.allow(RegExp("[0-9]")),
347+
],
348+
textInputAction: TextInputAction.done,
349+
onSubmitted: (value) => _beforeLogin(),
350+
decoration: InputDecoration(
351+
prefixIcon: const Icon(Icons.sms),
352+
border: const OutlineInputBorder(),
353+
labelText: '短信验证码',
354+
),
355+
),
356+
),
357+
),
358+
const SizedBox(height: 20),
331359
StreamBuilder(
332360
stream: _enableLogin.stream,
333361
builder: (_, snapshot) => FilledButton.tonal(

0 commit comments

Comments
 (0)