验证码倒计时

master
戴余标 3 years ago
parent 70251be997
commit 45d11faa1f

@ -4,6 +4,7 @@
import 'package:aku_new_community_manager/provider/app_provider.dart'; import 'package:aku_new_community_manager/provider/app_provider.dart';
import 'package:aku_new_community_manager/provider/data_provider.dart'; import 'package:aku_new_community_manager/provider/data_provider.dart';
import 'package:aku_new_community_manager/provider/message_provider.dart'; import 'package:aku_new_community_manager/provider/message_provider.dart';
import 'package:aku_new_community_manager/provider/timer_provider.dart';
import 'package:aku_new_community_manager/provider/user_provider.dart'; import 'package:aku_new_community_manager/provider/user_provider.dart';
import 'package:aku_new_community_manager/style/apptheme.dart'; import 'package:aku_new_community_manager/style/apptheme.dart';
import 'package:aku_new_community_manager/tools/user_tool.dart'; import 'package:aku_new_community_manager/tools/user_tool.dart';
@ -77,6 +78,7 @@ class MyApp extends StatelessWidget {
ChangeNotifierProvider(create: (context) => AppProvider()), ChangeNotifierProvider(create: (context) => AppProvider()),
ChangeNotifierProvider(create: (context) => MessageProvider()), ChangeNotifierProvider(create: (context) => MessageProvider()),
ChangeNotifierProvider(create: (context) => DataProvider()), ChangeNotifierProvider(create: (context) => DataProvider()),
ChangeNotifierProvider(create: (context) => ClockTimerProvider()),
], ],
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {

@ -5,9 +5,12 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:sms_autofill/sms_autofill.dart'; import 'package:sms_autofill/sms_autofill.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import '../../provider/timer_provider.dart';
class CodeMessagePage extends StatefulWidget { class CodeMessagePage extends StatefulWidget {
final String tel; final String tel;
@ -38,6 +41,7 @@ class _CodeMessagePageState extends State<CodeMessagePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ClockTimerProvider clockTimer = Provider.of<ClockTimerProvider>(context);
return AkuScaffold( return AkuScaffold(
title: '', title: '',
body: SafeArea( body: SafeArea(
@ -115,14 +119,14 @@ class _CodeMessagePageState extends State<CodeMessagePage> {
.communityModel!.id); .communityModel!.id);
if (base.success) { if (base.success) {
_errorMessage = null; _errorMessage = null;
UserTool.appProvider.startTimer(); clockTimer.startTimer();
} else { } else {
BotToast.showText(text: base.msg); BotToast.showText(text: base.msg);
} }
}, },
child: (UserTool.appProvider.second >= 60 child: (clockTimer.second >= 60
? '重新发送验证码' ? '重新发送验证码'
: '${UserTool.appProvider.second}秒后可重新发送') : '${clockTimer.second}秒后可重新发送')
.text .text
.size(28.sp) .size(28.sp)
.color(Color(0xFF5096F1)) .color(Color(0xFF5096F1))

@ -8,8 +8,10 @@ import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import '../../provider/timer_provider.dart';
import 'forgot_set_psd_page.dart'; import 'forgot_set_psd_page.dart';
class ForgotPsdPage extends StatefulWidget { class ForgotPsdPage extends StatefulWidget {
@ -30,6 +32,7 @@ class _ForgotPsdPageState extends State<ForgotPsdPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ClockTimerProvider clockTimer = Provider.of<ClockTimerProvider>(context);
return AkuScaffold( return AkuScaffold(
title: '', title: '',
backgroundColor: Colors.white, backgroundColor: Colors.white,
@ -84,7 +87,7 @@ class _ForgotPsdPageState extends State<ForgotPsdPage> {
Get.to(() => ForgotSetPsdPage( Get.to(() => ForgotSetPsdPage(
tel: _telController.text, tel: _telController.text,
)); ));
UserTool.appProvider.startTimer(); clockTimer.startTimer();
} else { } else {
BotToast.showText(text: base.msg); BotToast.showText(text: base.msg);
} }

@ -10,8 +10,11 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
import '../../provider/timer_provider.dart';
class ForgotSetPsdPage extends StatefulWidget { class ForgotSetPsdPage extends StatefulWidget {
final String tel; final String tel;
@ -52,6 +55,7 @@ class _ForgotSetPsdPageState extends State<ForgotSetPsdPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ClockTimerProvider clockTimer = Provider.of<ClockTimerProvider>(context);
return AkuScaffold( return AkuScaffold(
title: '', title: '',
backgroundColor: Colors.white, backgroundColor: Colors.white,
@ -129,7 +133,7 @@ class _ForgotSetPsdPageState extends State<ForgotSetPsdPage> {
Get.to(() => ForgotSetPsdPage( Get.to(() => ForgotSetPsdPage(
tel: widget.tel, tel: widget.tel,
)); ));
UserTool.appProvider.startTimer(); clockTimer.startTimer();
} else { } else {
BotToast.showText(text: base.msg); BotToast.showText(text: base.msg);
} }
@ -137,7 +141,7 @@ class _ForgotSetPsdPageState extends State<ForgotSetPsdPage> {
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
'${UserTool.appProvider.second < 60 ? '${UserTool.appProvider.second}秒后重新获取' : '获取验证码'}' '${clockTimer.second < 60 ? '${clockTimer.second}秒后重新获取' : '获取验证码'}'
.text .text
.size(28.sp) .size(28.sp)
.color(Color(0xFF5096F1)) .color(Color(0xFF5096F1))

@ -3,6 +3,7 @@ import 'package:aku_new_community_manager/new_ui/auth/widget/login_button_widget
import 'package:aku_new_community_manager/new_ui/auth/widget/psd_textfield.dart'; import 'package:aku_new_community_manager/new_ui/auth/widget/psd_textfield.dart';
import 'package:aku_new_community_manager/new_ui/auth/widget/tel_textfield.dart'; import 'package:aku_new_community_manager/new_ui/auth/widget/tel_textfield.dart';
import 'package:aku_new_community_manager/provider/app_provider.dart'; import 'package:aku_new_community_manager/provider/app_provider.dart';
import 'package:aku_new_community_manager/provider/timer_provider.dart';
import 'package:aku_new_community_manager/tools/user_tool.dart'; import 'package:aku_new_community_manager/tools/user_tool.dart';
import 'package:aku_new_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_new_community_manager/ui/widgets/common/aku_scaffold.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
@ -154,7 +155,7 @@ class _OtherLoginPageState extends State<OtherLoginPage> {
} }
Widget _verificationView() { Widget _verificationView() {
AppProvider appProvider = Provider.of<AppProvider>(context); ClockTimerProvider clockTimer = Provider.of<ClockTimerProvider>(context);
return ListView( return ListView(
padding: EdgeInsets.symmetric(horizontal: 32.w), padding: EdgeInsets.symmetric(horizontal: 32.w),
children: [ children: [
@ -171,7 +172,7 @@ class _OtherLoginPageState extends State<OtherLoginPage> {
), ),
100.w.heightBox, 100.w.heightBox,
LoginButtonWidget( LoginButtonWidget(
onTap: UserTool.appProvider.second < 60 onTap: clockTimer.second < 60
? () {} ? () {}
: () async { : () async {
var check = checkInput(); var check = checkInput();
@ -184,13 +185,13 @@ class _OtherLoginPageState extends State<OtherLoginPage> {
.communityModel!.id); .communityModel!.id);
if (base.success) { if (base.success) {
Get.to(() => CodeMessagePage(tel: _tel.text)); Get.to(() => CodeMessagePage(tel: _tel.text));
appProvider.startTimer(); clockTimer.startTimer();
} else { } else {
BotToast.showText(text: base.msg); BotToast.showText(text: base.msg);
} }
}, },
text: appProvider.timerStart text: clockTimer.timerStart
? '${appProvider.second}秒后重新获取' ? '${clockTimer.second}秒后重新获取'
: '获取验证码'), : '获取验证码'),
24.w.heightBox, 24.w.heightBox,
Row( Row(

@ -149,7 +149,7 @@ class AppProvider extends ChangeNotifier {
} }
/// ///
int second = 60; /*int second = 60;
bool timerStart = false; bool timerStart = false;
Timer? timer; Timer? timer;
@ -171,5 +171,6 @@ class AppProvider extends ChangeNotifier {
timer?.cancel(); timer?.cancel();
timer = null; timer = null;
notifyListeners(); notifyListeners();
} }*/
notifyListeners();
} }

@ -0,0 +1,30 @@
import 'dart:async';
import 'package:flutter/material.dart';
class ClockTimerProvider extends ChangeNotifier{
///
int second = 60;
bool timerStart = false;
Timer? timer;
void startTimer() {
timerStart = true;
timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (second > 0) {
second--;
notifyListeners();
} else {
stopTimer();
}
});
}
void stopTimer() {
second = 60;
timerStart = false;
timer?.cancel();
timer = null;
notifyListeners();
}
}

@ -3,6 +3,7 @@
import 'package:aku_new_community_manager/provider/app_provider.dart'; import 'package:aku_new_community_manager/provider/app_provider.dart';
import 'package:aku_new_community_manager/provider/data_provider.dart'; import 'package:aku_new_community_manager/provider/data_provider.dart';
import 'package:aku_new_community_manager/provider/message_provider.dart'; import 'package:aku_new_community_manager/provider/message_provider.dart';
import 'package:aku_new_community_manager/provider/timer_provider.dart';
import 'package:aku_new_community_manager/provider/user_provider.dart'; import 'package:aku_new_community_manager/provider/user_provider.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -25,5 +26,9 @@ class UserTool {
static DataProvider get dataProvider => static DataProvider get dataProvider =>
Provider.of<DataProvider>(Get.context!, listen: false); Provider.of<DataProvider>(Get.context!, listen: false);
///
static ClockTimerProvider get clockProvider =>
Provider.of<ClockTimerProvider>(Get.context!, listen: false);
UserTool(); UserTool();
} }

@ -25,7 +25,10 @@ class BeePickerBox extends StatelessWidget {
// height: 48.w, // height: 48.w,
child: TextButton( child: TextButton(
onPressed: onPressed, onPressed: onPressed,
child: Text(title,style: TextStyle(color: Colors.black.withOpacity(0.85)),), child: Text(
title,
style: TextStyle(color: Colors.black.withOpacity(0.85)),
),
), ),
); );
} }
@ -41,26 +44,42 @@ class BeePickerBox extends StatelessWidget {
children: [ children: [
SizedBox( SizedBox(
height: 88.w, height: 88.w,
child: NavigationToolbar( child: Row(
leading: TextButton( crossAxisAlignment: CrossAxisAlignment.stretch,
onPressed: () => Navigator.pop(context), children: [
child: Text( TextButton(
'取消', onPressed: () => Navigator.pop(context),
child: Text(
'取消',
style: TextStyle(
color: Colors.black,
fontSize: 28.sp,
),
),
), ),
), Spacer(),
middle: Text( Container(
title ?? '', padding: EdgeInsets.all(25.w),
style: TextStyle( child: Text(
color: kTextPrimaryColor, title ?? '',
fontSize: 28.sp, style: TextStyle(
color: kTextPrimaryColor,
fontSize: 28.sp,
),
),
), ),
), Spacer(),
trailing: TextButton( TextButton(
onPressed: onPressed, onPressed: onPressed,
child: Text( child: Text(
'${confirmString}', '${confirmString}',
style: TextStyle(
color: Colors.black,
fontSize: 28.sp,
),
),
), ),
), ],
), ),
), ),
BeeDivider.horizontal(), BeeDivider.horizontal(),

@ -618,6 +618,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.11" version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -958,7 +965,7 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.3" version: "0.4.8"
time: time:
dependency: transitive dependency: transitive
description: description:

Loading…
Cancel
Save