update_password_page.dart
4.05 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
import 'package:flutter/material.dart';
import 'package:Parlando/login/widgets/my_text_field.dart';
import 'package:Parlando/res/resources.dart';
import 'package:Parlando/routers/fluro_navigator.dart';
import 'package:Parlando/util/change_notifier_manage.dart';
import 'package:Parlando/util/other_utils.dart';
import 'package:Parlando/util/toast_utils.dart';
import 'package:Parlando/widgets/my_app_bar.dart';
import 'package:Parlando/widgets/my_button.dart';
import 'package:Parlando/widgets/my_scroll_view.dart';
import 'package:Parlando/extension/int_extension.dart';
import 'package:getwidget/components/loader/gf_loader.dart';
import '../../net/dio_utils.dart';
import '../../net/http_api.dart';
class UpdatePasswordPage extends StatefulWidget {
const UpdatePasswordPage({Key? key}) : super(key: key);
@override
_UpdatePasswordPageState createState() => _UpdatePasswordPageState();
}
class _UpdatePasswordPageState extends State<UpdatePasswordPage>
with ChangeNotifierMixin<UpdatePasswordPage> {
//定义一个controller
final TextEditingController _oldPwdController = TextEditingController();
final TextEditingController _newPwdController = TextEditingController();
final FocusNode _nodeText1 = FocusNode();
final FocusNode _nodeText2 = FocusNode();
bool _clickable = false;
bool _isLoading = false;
@override
Map<ChangeNotifier, List<VoidCallback>?>? changeNotifier() {
final List<VoidCallback> callbacks = <VoidCallback>[_verify];
return <ChangeNotifier, List<VoidCallback>?>{
_oldPwdController: callbacks,
_newPwdController: callbacks,
_nodeText1: null,
_nodeText2: null,
};
}
void _verify() {
final String oldPwd = _oldPwdController.text;
final String newPwd = _newPwdController.text;
bool clickable = true;
if (oldPwd.isEmpty || oldPwd.length < 6) {
clickable = false;
}
if (newPwd.isEmpty || newPwd.length < 6) {
clickable = false;
}
if (clickable != _clickable) {
setState(() {
_clickable = clickable;
});
}
}
void _confirm() {
_isLoading = true;
Map<String, String> params = <String, String>{
"password": _newPwdController.text,
"password_confirmation": _newPwdController.text,
};
DioUtils.instance.asyncRequestNetwork(
Method.post,
HttpApi.changePassword,
params: params,
onSuccess: (data) {
_isLoading = false;
NavigatorUtils.goBack(context);
},
onError: (code, msg) {
_isLoading = false;
Toast.show(msg.toString());
setState(() {});
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const MyAppBar(),
body: MyScrollView(
keyboardConfig: Utils.getKeyboardActionsConfig(
context, <FocusNode>[_nodeText1, _nodeText2]),
crossAxisAlignment: CrossAxisAlignment.center,
padding: EdgeInsets.only(left: 16.px, right: 16.px, top: 20.px),
children: <Widget>[
const Text(
'重置登录密码',
style: TextStyles.textBold26,
),
Gaps.vGap8,
Text(
' ',
style: Theme.of(context)
.textTheme
.subtitle2
?.copyWith(fontSize: Dimens.font_sp12),
),
Gaps.vGap32,
MyTextField(
isInputPwd: true,
focusNode: _nodeText1,
controller: _oldPwdController,
keyboardType: TextInputType.visiblePassword,
hintText: '请确认旧密码',
),
Gaps.vGap8,
MyTextField(
isInputPwd: true,
focusNode: _nodeText2,
controller: _newPwdController,
keyboardType: TextInputType.visiblePassword,
hintText: '请输入新密码',
),
Gaps.vGap24,
MyButton(
onPressed: _clickable ? _confirm : null,
text: '确认',
),
Container(
child: _isLoading ? const GFLoader() : null,
),
],
),
);
}
}