revise_password_page.dart 6.2 KB

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