From e55fb2a1ebb02761c166afd20d2fa500b6d3be66 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Tue, 19 Jan 2021 10:41:53 +0800 Subject: [PATCH] add update telphone --- lib/pages/personal/update_tel_page.dart | 51 ++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/pages/personal/update_tel_page.dart b/lib/pages/personal/update_tel_page.dart index 898b1808..c52400ec 100644 --- a/lib/pages/personal/update_tel_page.dart +++ b/lib/pages/personal/update_tel_page.dart @@ -1,6 +1,11 @@ +import 'dart:async'; + import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/pages/sign/sign_func.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:bot_toast/bot_toast.dart'; +import 'package:flustars/flustars.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; @@ -18,6 +23,13 @@ class _UpdateTelPageState extends State { TextEditingController _oldTelController; TextEditingController _newTelController; TextEditingController _codeController; + Timer _timer; + bool get validPhone => RegexUtil.isMobileSimple(_newTelController.text); + bool get _canGetCode { + bool timeActive = _timer?.isActive ?? false; + return (!timeActive) && validPhone; + } + @override void initState() { // final userProvider = Provider.of(context, listen: false); @@ -35,6 +47,16 @@ class _UpdateTelPageState extends State { super.dispose(); } + startTick() { + _timer = Timer.periodic(Duration(seconds: 1), (_timer) { + if (_timer.tick >= 60) { + _timer.cancel(); + _timer = null; + } + setState(() {}); + }); + } + @override Widget build(BuildContext context) { final userProvider = Provider.of(context); @@ -70,8 +92,19 @@ class _UpdateTelPageState extends State { suffixIconConstraints: BoxConstraints(minHeight: 0.w, minWidth: 0.w), suffixIcon: MaterialButton( - onPressed: () {}, - child: '获取验证码'.text.color(kPrimaryColor).size(28.sp).make(), + onPressed: _canGetCode + ? () { + SignFunc.sendMessageCode(_newTelController.text); + startTick(); + } + : () {}, + child: _timer?.isActive ?? false + ? '${60 - _timer.tick}' + .text + .color(kPrimaryColor) + .size(28.sp) + .make() + : '获取验证码'.text.color(kPrimaryColor).size(28.sp).make(), padding: EdgeInsets.zero, minWidth: 177.w, height: 62.w, @@ -117,9 +150,17 @@ class _UpdateTelPageState extends State { 64.heightBox, MaterialButton( onPressed: () { - userProvider.updateTel(_oldTelController.text, - _newTelController.text, _codeController.text); - Get.back(); + if (TextUtil.isEmpty(_oldTelController.text)) { + BotToast.showText(text: '旧手机号不能为空'); + } else if (TextUtil.isEmpty(_newTelController.text)) { + BotToast.showText(text: '新手机号不能为空'); + } else if (TextUtil.isEmpty(_codeController.text)) { + BotToast.showText(text: '验证码不能为空'); + } else { + userProvider.updateTel(_oldTelController.text, + _newTelController.text, _codeController.text); + Get.back(); + } }, child: '保存'.text.black.size(32.sp).make(), color: Color(0xFFFFC40C),