revise_password_page.dart 6.8 KB

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