revise_password_page.dart 5.9 KB

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