change_pwd_page.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
  5. import 'package:lszlgl/base/base_state.dart';
  6. import 'package:lszlgl/widget/button.dart';
  7. import 'package:lszlgl/widget/card_item.dart';
  8. /// 修改密码
  9. class ChangePwdPage extends StatefulWidget {
  10. const ChangePwdPage({Key? key}) : super(key: key);
  11. @override
  12. State<ChangePwdPage> createState() => _ChangePwdPageState();
  13. }
  14. class _ChangePwdPageState extends BaseState<ChangePwdPage> {
  15. int countDown = 0;
  16. Timer? timer;
  17. void startTimer() {
  18. timer?.cancel();
  19. setState(() => countDown = 60);
  20. timer = Timer.periodic(const Duration(seconds: 1), (timer) {
  21. setState(() => countDown--);
  22. if (countDown == 0) timer.cancel();
  23. });
  24. }
  25. void onChange() {
  26. MyNavigator.showToast('修改成功');
  27. MyNavigator.pop();
  28. }
  29. @override
  30. void dispose() {
  31. timer?.cancel();
  32. super.dispose();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return myScaffold(
  37. child: KeyboardDismissOnTap(
  38. dismissOnCapturedTaps: true,
  39. child: buildBody(),
  40. ),
  41. );
  42. }
  43. Widget buildBody() {
  44. return Column(
  45. children: [
  46. myAppBar(title: '修改密码'),
  47. buildList(),
  48. const SizedBox(height: 32),
  49. MyButton(
  50. '确认修改',
  51. onTap: onChange,
  52. gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
  53. alignment: Alignment.center,
  54. minHeight: 40,
  55. margin: const EdgeInsets.symmetric(horizontal: 24),
  56. ),
  57. ],
  58. );
  59. }
  60. Widget buildList() {
  61. return Container(
  62. margin: const EdgeInsets.symmetric(horizontal: 12),
  63. clipBehavior: Clip.hardEdge,
  64. decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(10))),
  65. child: Column(
  66. children: [
  67. CardItemWidget(
  68. '短信验证码',
  69. rightChild: buildSmsCode(),
  70. bottomLine: true,
  71. ),
  72. CardItemWidget(
  73. '新密码',
  74. rightChild: buildNewPwd(),
  75. ),
  76. ],
  77. ),
  78. );
  79. }
  80. Widget buildSmsCode() {
  81. return Row(
  82. children: [
  83. Expanded(
  84. child: TextField(
  85. keyboardType: TextInputType.number,
  86. textAlign: TextAlign.right,
  87. decoration: const InputDecoration(
  88. hintText: '请输入',
  89. border: InputBorder.none,
  90. contentPadding: EdgeInsets.zero,
  91. isDense: true,
  92. counterText: '',
  93. ),
  94. style: const TextStyle(fontSize: 14),
  95. maxLength: 6,
  96. inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'\d'))],
  97. ),
  98. ),
  99. const SizedBox(width: 16),
  100. SizedBox(
  101. height: 32,
  102. child: FilledButton(
  103. onPressed: countDown > 0 ? null : startTimer,
  104. style: FilledButton.styleFrom(backgroundColor: const Color(0xFF25A6EE)),
  105. child: Text(countDown > 0 ? '${countDown}s' : '发送'),
  106. ),
  107. ),
  108. ],
  109. );
  110. }
  111. Widget buildNewPwd() {
  112. return const TextField(
  113. keyboardType: TextInputType.visiblePassword,
  114. textAlign: TextAlign.right,
  115. decoration: InputDecoration(
  116. hintText: '至少6位字符或者数字',
  117. border: InputBorder.none,
  118. contentPadding: EdgeInsets.zero,
  119. isDense: true,
  120. ),
  121. style: TextStyle(fontSize: 14),
  122. inputFormatters: [],
  123. );
  124. }
  125. }