revise_password_page.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:crypto/crypto.dart';
  4. import 'dart:convert';
  5. import '../../util/session.dart';
  6. import '../../showAlert.dart';
  7. import '../../util/api.dart';
  8. import '../../util/util.dart';
  9. import '../../login_page.dart';
  10. class RevisePasswordPage extends StatefulWidget {
  11. final Widget child;
  12. RevisePasswordPage({
  13. Key key,
  14. this.child
  15. }): super(key: key);
  16. _RevisePasswordPageState createState() => _RevisePasswordPageState();
  17. }
  18. class _RevisePasswordPageState extends State < RevisePasswordPage > {
  19. String oldPassword = '';
  20. String newPassword = '';
  21. bool submitStatus = false;
  22. bool loginStatus = true;
  23. @override
  24. Widget build(BuildContext context) {
  25. return Scaffold(
  26. appBar: AppBar(
  27. elevation: 0,
  28. title: Text('修改密码',
  29. style: TextStyle(
  30. fontSize: ScreenUtil.getInstance().setSp(36)
  31. ), ),
  32. centerTitle: true,
  33. backgroundColor: Color.fromRGBO(64, 98, 254, 1),
  34. ),
  35. body: Container(
  36. color: Colors.white,
  37. child: Column(
  38. children: < Widget > [
  39. Container(
  40. padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(55), ScreenUtil.getInstance().setHeight(150), ScreenUtil.getInstance().setHeight(55), 0),
  41. child: Column(
  42. children: < Widget > [
  43. Padding(
  44. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(60)),
  45. child: TextField(
  46. obscureText: true,
  47. decoration: InputDecoration(
  48. border: UnderlineInputBorder(),
  49. hintText: "请输入旧密码",
  50. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Color.fromRGBO(155, 155, 155, 1)),
  51. ),
  52. onChanged: (value) {
  53. setState(() {
  54. oldPassword = value;
  55. });
  56. },
  57. ),
  58. ),
  59. Padding(
  60. padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(125)),
  61. child: TextField(
  62. obscureText: true,
  63. cursorColor: Color.fromRGBO(153, 153, 153, 0.5),
  64. decoration: InputDecoration(
  65. hintText: "请输入新密码",
  66. hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Color.fromRGBO(155, 155, 155, 1)),
  67. ),
  68. onChanged: (value) {
  69. setState(() {
  70. newPassword = value;
  71. });
  72. },
  73. )
  74. ),
  75. InkWell(
  76. child: Container(
  77. height: ScreenUtil.getInstance().setHeight(100),
  78. decoration: BoxDecoration(
  79. color: (oldPassword != '' && newPassword != '') ? Color.fromRGBO(64, 98, 254, 1) : Colors.grey,
  80. borderRadius: BorderRadius.circular(4),
  81. ),
  82. child: Center(
  83. child: Row(
  84. mainAxisAlignment: MainAxisAlignment.center,
  85. children: < Widget > [
  86. Offstage(
  87. offstage: loginStatus,
  88. child: SizedBox(
  89. width: ScreenUtil.getInstance().setWidth(45),
  90. height: ScreenUtil.getInstance().setHeight(45),
  91. child: Image.asset('lib/images/loading.gif'),
  92. ),
  93. ),
  94. Text('确定', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
  95. ],
  96. )
  97. ),
  98. ),
  99. onTap: () {
  100. if (oldPassword == '' || newPassword == '') {
  101. return;
  102. }
  103. String tempString = sha1.convert(utf8.encode(oldPassword)).toString();
  104. String newTempString = sha1.convert(utf8.encode(newPassword)).toString();
  105. getKey('password').then((value) {
  106. if (value != tempString) {
  107. showDialog < Null > (
  108. context: context, //BuildContext对象
  109. barrierDismissible: false,
  110. builder: (BuildContext context) {
  111. return new MyAlertDialog( //调用对话框
  112. text: '旧密码错误,请重新输入', childCallback: (val) {},
  113. );
  114. });
  115. } else {
  116. setState(() {
  117. loginStatus = false;
  118. });
  119. updataPasswrod(tempString, newTempString).then((resp) {
  120. if (isNotError(context, resp) && this.mounted) {
  121. setKey('password', newTempString);
  122. showDialog < Null > (
  123. context: context, //BuildContext对象
  124. barrierDismissible: false,
  125. builder: (BuildContext context) {
  126. return new MyAlertDialog( //调用对话框
  127. text: '修改成功', childCallback: (val) {
  128. if (val) {
  129. setState(() {
  130. loginStatus = true;
  131. });
  132. clearKey();
  133. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
  134. return LoginPage();
  135. }));
  136. }
  137. },
  138. );
  139. });
  140. }
  141. });
  142. }
  143. });
  144. },
  145. )
  146. ],
  147. ),
  148. )
  149. ],
  150. ),
  151. ),
  152. resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误
  153. );
  154. }
  155. }