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 createState() => _ChangePwdPageState(); } class _ChangePwdPageState extends BaseState { 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: [], ); } }