register_page.dart
5.83 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
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
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:one_poem/home/webview_page.dart';
import 'package:one_poem/login/widgets/my_text_field.dart';
import 'package:one_poem/res/resources.dart';
import 'package:one_poem/res/styles.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 'package:flutter_gen/gen_l10n/one_poem_localizations.dart';
import 'package:one_poem/extension/int_extension.dart';
/// design/1注册登录/index.html#artboard11
class RegisterPage extends StatefulWidget {
const RegisterPage({Key? key}) : super(key: key);
@override
_RegisterPageState createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage>
with ChangeNotifierMixin<RegisterPage> {
//定义一个controller
final TextEditingController _nameController = TextEditingController();
final TextEditingController _vCodeController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final FocusNode _nodeText1 = FocusNode();
final FocusNode _nodeText2 = FocusNode();
final FocusNode _nodeText3 = FocusNode();
bool _clickable = false;
bool _switchSelected=true;
@override
Map<ChangeNotifier, List<VoidCallback>?>? changeNotifier() {
final List<VoidCallback> callbacks = <VoidCallback>[_verify];
return <ChangeNotifier, List<VoidCallback>?>{
_nameController: callbacks,
_vCodeController: callbacks,
_passwordController: callbacks,
_nodeText1: null,
_nodeText2: null,
_nodeText3: null,
};
}
void _verify() {
final String name = _nameController.text;
final String vCode = _vCodeController.text;
final String password = _passwordController.text;
bool clickable = true;
if (name.isEmpty || name.length < 11) {
clickable = false;
}
if (vCode.isEmpty || vCode.length < 6) {
clickable = false;
}
if (password.isEmpty || password.length < 6) {
clickable = false;
}
if (clickable != _clickable) {
setState(() {
_clickable = clickable;
});
}
}
void _register() {
Toast.show('点击注册');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const MyAppBar(),
body: MyScrollView(
keyboardConfig: Utils.getKeyboardActionsConfig(
context, <FocusNode>[_nodeText1, _nodeText2, _nodeText3]),
crossAxisAlignment: CrossAxisAlignment.center,
padding: EdgeInsets.only(left: 16.px, right: 16.px, top: 20.px),
children: _buildBody(),
),
);
}
List<Widget> _buildBody() {
return <Widget>[
Text(
OnePoemLocalizations.of(context).openYourAccount,
style: TextStyles.textBold26,
),
Gaps.vGap16,
MyTextField(
key: const Key('phone'),
focusNode: _nodeText1,
controller: _nameController,
maxLength: 11,
keyboardType: TextInputType.phone,
hintText: OnePoemLocalizations.of(context).inputPhoneHint,
),
Gaps.vGap8,
MyTextField(
key: const Key('vcode'),
focusNode: _nodeText2,
controller: _vCodeController,
keyboardType: TextInputType.number,
getVCode: () async {
if (_nameController.text.length == 11) {
Toast.show(OnePoemLocalizations.of(context).verificationButton);
/// 一般可以在这里发送真正的请求,请求成功返回true
return true;
} else {
Toast.show(OnePoemLocalizations.of(context).inputPhoneInvalid);
return false;
}
},
maxLength: 6,
hintText: OnePoemLocalizations.of(context).inputVerificationCodeHint,
),
Gaps.vGap8,
MyTextField(
key: const Key('password'),
keyName: 'password',
focusNode: _nodeText3,
isInputPwd: true,
controller: _passwordController,
keyboardType: TextInputType.visiblePassword,
hintText: OnePoemLocalizations.of(context).inputPasswordHint,
),
Gaps.vGap8,
Text.rich(
TextSpan(
text: '登录即代表同意并阅读',
style: TextStyle(fontSize: 14, color: const Color(0xFF999999)),
children: [
TextSpan(
text: '《用户协议》',
style: TextStyle(color: Theme.of(context).primaryColor),
recognizer: TapGestureRecognizer()
..onTap = () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return WebViewPage(
title: '《用户协议》', url: 'https://flutter.dev');
}));
},
),
TextSpan(text: '和'),
TextSpan(
text: '《隐私政策》',
style: TextStyle(color: Theme.of(context).primaryColor),
recognizer: TapGestureRecognizer()
..onTap = () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) {
return WebViewPage(
title: '《隐私政策》', url: 'https://flutter.dev');
}));
},
),
]),
),
Gaps.vGap24,
MyButton(
key: const Key('register'),
onPressed: _clickable ? _register : null,
text: OnePoemLocalizations.of(context).register,
)
];
}
}