ChangePassword.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:flutter/material.dart';
  2. import '../widget/ITextInput.dart';
  3. import '../widget/LinearButton.dart';
  4. import '../net/HttpManager.dart';
  5. import '../net/Result.dart';
  6. import 'package:redux/redux.dart';
  7. import 'package:flutter_redux/flutter_redux.dart';
  8. import '../redux/AppState.dart';
  9. import '../model/UserInfo.dart';
  10. import '../styles/totast.dart';
  11. class ChangePassword extends StatefulWidget {
  12. @override
  13. _ChangePasswordState createState() => _ChangePasswordState();
  14. }
  15. class _ChangePasswordState extends State<ChangePassword> with WidgetsBindingObserver {
  16. String password_old = '';
  17. String password_new = '';
  18. String password_se = '';
  19. @override
  20. Widget build(BuildContext context) {
  21. return StoreConnector<AppState, UserInfo>(
  22. converter: (Store store) => store.state.userInfo,
  23. builder: (context, userInfo) {
  24. return Scaffold(
  25. appBar: AppBar(
  26. title: Text('修改密码'),
  27. ),
  28. backgroundColor: Color(0xFF23253C),
  29. body: Column(
  30. children: <Widget>[
  31. Container(
  32. height: 10,
  33. ),
  34. ITextField(
  35. keyboardType: ITextInputType.password,
  36. prefixIcon: Container(
  37. child: Image.asset(
  38. 'images/list_icon_yanzhengma.png',
  39. width: 20,
  40. ),
  41. ),
  42. hintText: '请输入您的原始密码',
  43. hintStyle: TextStyle(
  44. fontSize: 16,
  45. color: Color(0xFF727785),
  46. ),
  47. textStyle: TextStyle(color: Colors.white),
  48. fieldCallBack: (content) {
  49. setState(() {
  50. password_old = content;
  51. });
  52. },
  53. counterStyle: TextStyle(color: Color(0xFF000000), fontSize: 0),
  54. ),
  55. Container(
  56. height: 10,
  57. ),
  58. ITextField(
  59. keyboardType: ITextInputType.password,
  60. prefixIcon: Container(
  61. child: Image.asset(
  62. 'images/list_icon_yanzhengma.png',
  63. width: 20,
  64. ),
  65. ),
  66. hintText: '请设置您的新密码',
  67. hintStyle: TextStyle(
  68. fontSize: 16,
  69. color: Color(0xFF727785),
  70. ),
  71. textStyle: TextStyle(color: Colors.white),
  72. fieldCallBack: (content) {
  73. setState(() {
  74. password_new = content;
  75. });
  76. },
  77. counterStyle: TextStyle(color: Color(0xFF000000), fontSize: 0),
  78. ),
  79. Container(
  80. height: 10,
  81. ),
  82. ITextField(
  83. keyboardType: ITextInputType.password,
  84. prefixIcon: Container(
  85. child: Image.asset(
  86. 'images/list_icon_yanzhengma.png',
  87. width: 20,
  88. ),
  89. ),
  90. hintText: '请确认您的新密码',
  91. hintStyle: TextStyle(
  92. fontSize: 16,
  93. color: Color(0xFF727785),
  94. ),
  95. textStyle: TextStyle(color: Colors.white),
  96. fieldCallBack: (content) {
  97. setState(() {
  98. password_se = content;
  99. });
  100. },
  101. counterStyle: TextStyle(color: Color(0xFF000000), fontSize: 0),
  102. ),
  103. Container(
  104. height: 52,
  105. ),
  106. Padding(
  107. padding: EdgeInsets.symmetric(horizontal: 15),
  108. child: LinearButton(
  109. btnHeight: 48.0,
  110. btntext: '确认修改',
  111. textColor: (password_new == password_se && password_se != '' && password_old != '') ? Colors.white : Color(0xFF15151D),
  112. colorList: (password_new == password_se && password_se != '' && password_old != '')
  113. ? [Color(0xFFD4504B), Color(0xFFD4504B)]
  114. : [Color(0xFF727785), Color(0xFF727785)],
  115. onTapHomeMenu: (password_new == password_se && password_se != '' && password_old != '')
  116. ? () async {
  117. Toast.show(context, '加载中', -1, 'loading');
  118. Result res = await HttpManager.post('userInfo/changePassword',
  119. data: {"userId": userInfo.id, "oldPassword": password_old, "newPassword": password_new});
  120. Toast.hide();
  121. if (res.success) {
  122. Toast.show(context, '修改成功', 1500, 'success');
  123. Navigator.of(context).pop();
  124. } else {
  125. Toast.show(context, res.error, 1500, 'info');
  126. }
  127. }
  128. : null,
  129. ),
  130. )
  131. ],
  132. ),
  133. );
  134. });
  135. }
  136. }