v1.1.1otp_timer_button
此包用于轻松实现 OTP 计时按钮,该按钮将在指定时间后启用。
39喜欢 796近 30 天下载150Pub 分数
AndroidiOSWebmacOSWindowsLinux
这是一个用于轻松实现OTP计时按钮的Flutter包。
以下为英文项目原文快照,最新内容请访问 GitHub。
This is a Flutter package for easy implementation otp timer button.

Add the following to your pubspec.yaml file:
dependencies:
otp_timer_button: ^1.1.1
import 'package:otp_timer_button/otp_timer_button.dart';
OtpTimerButtonController controller = OtpTimerButtonController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: OtpTimerButton(
controller: controller,
onPressed: () {},
text: Text('Resend OTP'),
duration: 60,
),
),
);
}
If you want to wait for the response to the OTP request, you can use the controller:
NOTE: if use controller, auto start timer is disabled on pressed button.
OtpTimerButtonController controller = OtpTimerButtonController();
_requestOtp() {
controller.loading();
Future.delayed(Duration(seconds: 2), () {
controller.startTimer();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: OtpTimerButton(
controller: controller,
onPressed: () => _requestOtp(),
text: Text('Resend OTP'),
duration: 2,
),
),
);
}

controller.startTimer();
controller.loading();
controller.enableButton();
OtpTimerButton(
controller: controller,
height: 60,
text: Text(
'Resend OTP',
),
duration: 60,
radius: 30,
backgroundColor: Colors.blue,
textColor: Colors.white,
buttonType: ButtonType.text_button, // or ButtonType.outlined_button
loadingIndicator: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.red,
),
loadingIndicatorColor: Colors.red,
onPressed: () {},
),
依赖清单 2 项
{"sdk":"flutter"}{"sdk":"flutter"}先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗