sms_login_page.dart
4.33 KB
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
import 'dart:ui';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:one_poem/generated/l10n.dart';
import 'package:one_poem/login/widgets/my_text_field.dart';
import 'package:one_poem/res/resources.dart';
import 'package:one_poem/routers/fluro_navigator.dart';
import 'package:one_poem/util/change_notifier_manage.dart';
import 'package:one_poem/util/other_utils.dart';
import 'package:one_poem/util/toast_utils.dart';
import 'package:one_poem/widgets/my_app_bar.dart';
import 'package:one_poem/widgets/my_button.dart';
import 'package:one_poem/widgets/my_scroll_view.dart';
import '../login_router.dart';
/// design/1注册登录/index.html#artboard4
class SMSLoginPage extends StatefulWidget {
const SMSLoginPage({Key? key}) : super(key: key);
@override
_SMSLoginPageState createState() => _SMSLoginPageState();
}
class _SMSLoginPageState extends State<SMSLoginPage> with ChangeNotifierMixin<SMSLoginPage> {
final TextEditingController _phoneController = TextEditingController();
final TextEditingController _vCodeController = TextEditingController();
final FocusNode _nodeText1 = FocusNode();
final FocusNode _nodeText2 = FocusNode();
bool _clickable = false;
@override
Map<ChangeNotifier, List<VoidCallback>?>? changeNotifier() {
final List<VoidCallback> callbacks = <VoidCallback>[_verify];
return <ChangeNotifier, List<VoidCallback>?>{
_phoneController: callbacks,
_vCodeController: callbacks,
_nodeText1: null,
_nodeText2: null,
};
}
void _verify() {
final String name = _phoneController.text;
final String vCode = _vCodeController.text;
bool clickable = true;
if (name.isEmpty || name.length < 11) {
clickable = false;
}
if (vCode.isEmpty || vCode.length < 6) {
clickable = false;
}
if (clickable != _clickable) {
setState(() {
_clickable = clickable;
});
}
}
void _login() {
Toast.show('去登录......');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const MyAppBar(),
body: MyScrollView(
keyboardConfig: Utils.getKeyboardActionsConfig(context, <FocusNode>[_nodeText1, _nodeText2]),
padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 20.0),
children: _buildBody(),
),
);
}
List<Widget> _buildBody() {
return <Widget>[
Text(
S.of(context).verificationCodeLogin,
style: TextStyles.textBold26,
),
Gaps.vGap16,
MyTextField(
focusNode: _nodeText1,
controller: _phoneController,
maxLength: 11,
keyboardType: TextInputType.phone,
hintText: S.of(context).inputPhoneHint,
),
Gaps.vGap8,
MyTextField(
focusNode: _nodeText2,
controller: _vCodeController,
maxLength: 6,
keyboardType: TextInputType.number,
hintText: S.of(context).inputVerificationCodeHint,
getVCode: () {
Toast.show(S.of(context).getVerificationCode);
return Future<bool>.value(true);
},
),
Gaps.vGap8,
Container(
alignment: Alignment.centerLeft,
child: RichText(
text: TextSpan(
text: S.of(context).registeredTips,
style: Theme.of(context).textTheme.subtitle2?.copyWith(fontSize: Dimens.font_sp14),
children: <TextSpan>[
TextSpan(
text: S.of(context).register,
style: TextStyle(
color: Theme.of(context).errorColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
NavigatorUtils.push(context, LoginRouter.registerPage);
},
),
TextSpan(text: Utils.getCurrLocale() == 'zh' ? '。' : '.',),
],
),
),
),
Gaps.vGap24,
MyButton(
onPressed: _clickable ? _login : null,
text: S.of(context).login,
),
Container(
height: 40.0,
alignment: Alignment.centerRight,
child: GestureDetector(
child: Text(
S.of(context).forgotPasswordLink,
style: Theme.of(context).textTheme.subtitle2,
),
onTap: () => NavigatorUtils.push(context, LoginRouter.resetPasswordPage),
),
)
];
}
}