revise_password_page.dart 6.5 KB

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