123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
- import 'package:lszlgl/base/base_state.dart';
- import 'package:lszlgl/widget/button.dart';
- import 'package:lszlgl/widget/card_item.dart';
- /// 修改密码
- class ChangePwdPage extends StatefulWidget {
- const ChangePwdPage({Key? key}) : super(key: key);
- @override
- State<ChangePwdPage> createState() => _ChangePwdPageState();
- }
- class _ChangePwdPageState extends BaseState<ChangePwdPage> {
- int countDown = 0;
- Timer? timer;
- void startTimer() {
- timer?.cancel();
- setState(() => countDown = 60);
- timer = Timer.periodic(const Duration(seconds: 1), (timer) {
- setState(() => countDown--);
- if (countDown == 0) timer.cancel();
- });
- }
- void onChange() {
- MyNavigator.showToast('修改成功');
- MyNavigator.pop();
- }
- @override
- void dispose() {
- timer?.cancel();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return myScaffold(
- child: KeyboardDismissOnTap(
- dismissOnCapturedTaps: true,
- child: buildBody(),
- ),
- );
- }
- Widget buildBody() {
- return Column(
- children: [
- myAppBar(title: '修改密码'),
- buildList(),
- const SizedBox(height: 32),
- MyButton(
- '确认修改',
- onTap: onChange,
- gradient: const LinearGradient(colors: [Color(0xFF3BD2E5), Color(0xFF247AF8)]),
- alignment: Alignment.center,
- minHeight: 40,
- margin: const EdgeInsets.symmetric(horizontal: 24),
- ),
- ],
- );
- }
- Widget buildList() {
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 12),
- clipBehavior: Clip.hardEdge,
- decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(10))),
- child: Column(
- children: [
- CardItemWidget(
- '短信验证码',
- rightChild: buildSmsCode(),
- bottomLine: true,
- ),
- CardItemWidget(
- '新密码',
- rightChild: buildNewPwd(),
- ),
- ],
- ),
- );
- }
- Widget buildSmsCode() {
- return Row(
- children: [
- Expanded(
- child: TextField(
- keyboardType: TextInputType.number,
- textAlign: TextAlign.right,
- decoration: const InputDecoration(
- hintText: '请输入',
- border: InputBorder.none,
- contentPadding: EdgeInsets.zero,
- isDense: true,
- counterText: '',
- ),
- style: const TextStyle(fontSize: 14),
- maxLength: 6,
- inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'\d'))],
- ),
- ),
- const SizedBox(width: 16),
- SizedBox(
- height: 32,
- child: FilledButton(
- onPressed: countDown > 0 ? null : startTimer,
- style: FilledButton.styleFrom(backgroundColor: const Color(0xFF25A6EE)),
- child: Text(countDown > 0 ? '${countDown}s' : '发送'),
- ),
- ),
- ],
- );
- }
- Widget buildNewPwd() {
- return const TextField(
- keyboardType: TextInputType.visiblePassword,
- textAlign: TextAlign.right,
- decoration: InputDecoration(
- hintText: '至少6位字符或者数字',
- border: InputBorder.none,
- contentPadding: EdgeInsets.zero,
- isDense: true,
- ),
- style: TextStyle(fontSize: 14),
- inputFormatters: [],
- );
- }
- }
|