reset_password_page.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:keyboard_actions/keyboard_actions.dart';
  5. import 'package:liftmanager/net/api_service.dart';
  6. import 'package:liftmanager/res/resources.dart';
  7. import 'package:liftmanager/routers/fluro_navigator.dart';
  8. import 'package:liftmanager/utils/theme_utils.dart';
  9. import 'package:liftmanager/utils/toast.dart';
  10. import 'package:liftmanager/utils/utils.dart';
  11. import 'package:liftmanager/widgets/app_bar.dart';
  12. import 'package:liftmanager/widgets/my_button.dart';
  13. import 'package:liftmanager/widgets/text_field.dart';
  14. /// design/1注册登录/index.html#artboard9
  15. class ResetPasswordPage extends StatefulWidget {
  16. @override
  17. _ResetPasswordPageState createState() => _ResetPasswordPageState();
  18. }
  19. class _ResetPasswordPageState extends State<ResetPasswordPage> {
  20. //定义一个controller
  21. TextEditingController _phoneController = TextEditingController();
  22. TextEditingController _vCodeController = TextEditingController();
  23. TextEditingController _passwordController = TextEditingController();
  24. final FocusNode _nodeText1 = FocusNode();
  25. final FocusNode _nodeText2 = FocusNode();
  26. final FocusNode _nodeText3 = FocusNode();
  27. bool _isClick = false;
  28. @override
  29. void initState() {
  30. super.initState();
  31. //监听输入改变
  32. _phoneController.addListener(_verify);
  33. _vCodeController.addListener(_verify);
  34. _passwordController.addListener(_verify);
  35. }
  36. Future<bool> _getVCode() async {
  37. await ApiService(context: context).getVCode(_phoneController.text.toString().trim(),
  38. onSuccess: (data) {
  39. print("成功");
  40. }, onError: (code, msg) {
  41. toasts(msg);
  42. });
  43. return Future.value(true);
  44. }
  45. void _verify(){
  46. String name = _phoneController.text;
  47. String vCode = _vCodeController.text;
  48. String password = _passwordController.text;
  49. bool isClick = true;
  50. if (name.isEmpty || name.length < 11) {
  51. isClick = false;
  52. }
  53. if (vCode.isEmpty || vCode.length < 6) {
  54. isClick = false;
  55. }
  56. if (password.isEmpty || password.length < 6) {
  57. isClick = false;
  58. }
  59. if (isClick != _isClick){
  60. setState(() {
  61. _isClick = isClick;
  62. });
  63. }
  64. }
  65. void _reset(){
  66. String phone = _phoneController.text;
  67. String vCode = _vCodeController.text;
  68. String password = _passwordController.text;
  69. showLoading(context, "正在执行...");
  70. ApiService(context: context).resetPassword(
  71. phone, Utils.generateMd5(password), vCode,
  72. onSuccess: (data) {
  73. dismissLoading(context);
  74. showAlert(context, "提示", "重置成功,请登录", "确定", (){
  75. NavigatorUtils.goBack(context);
  76. NavigatorUtils.goBack(context);
  77. });
  78. }, onError: (code, msg) {
  79. dismissLoading(context);
  80. toasts(msg);
  81. });
  82. }
  83. @override
  84. Widget build(BuildContext context) {
  85. return Scaffold(
  86. backgroundColor: ThemeUtils.getTabsBg(context),
  87. appBar: const MyAppBar(
  88. centerTitle: "忘记密码",
  89. ),
  90. body: defaultTargetPlatform == TargetPlatform.iOS ? FormKeyboardActions(
  91. child: _buildBody(),
  92. ) : SingleChildScrollView(
  93. child: _buildBody(),
  94. )
  95. );
  96. }
  97. _buildBody(){
  98. return Padding(
  99. padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 20.0),
  100. child: Column(
  101. crossAxisAlignment: CrossAxisAlignment.center,
  102. children: <Widget>[
  103. Gaps.vGap16,
  104. MyTextField(
  105. focusNode: _nodeText1,
  106. config: Utils.getKeyboardActionsConfig(context, [_nodeText1, _nodeText2, _nodeText3]),
  107. controller: _phoneController,
  108. maxLength: 11,
  109. keyboardType: TextInputType.phone,
  110. hintText: "请输入手机号",
  111. ),
  112. Gaps.vGap8,
  113. MyTextField(
  114. focusNode: _nodeText2,
  115. controller: _vCodeController,
  116. keyboardType: TextInputType.number,
  117. getVCode: () async {
  118. if (_phoneController.text.toString().trim().length == 11) {
  119. return await _getVCode();
  120. } else {
  121. toasts("请输入有效的手机号");
  122. return false;
  123. }
  124. },
  125. maxLength: 6,
  126. hintText: "请输入验证码",
  127. ),
  128. Gaps.vGap8,
  129. MyTextField(
  130. focusNode: _nodeText3,
  131. isInputPwd: true,
  132. controller: _passwordController,
  133. maxLength: 16,
  134. keyboardType: TextInputType.visiblePassword,
  135. hintText: "请输入密码",
  136. ),
  137. Gaps.vGap10,
  138. Gaps.vGap15,
  139. MyButton(
  140. onPressed: _isClick ? _reset : null,
  141. text: "确认",
  142. )
  143. ],
  144. ),
  145. );
  146. }
  147. }