//定义timer
Timer? myTimer;
//Time初始化和倒计时
myTimer = Timer.periodic(Duration(seconds: 1), (timer) {
if (state.initialCountdown > 0) {
state.initialCountdown--;
print("点击倒计时${state.initialCountdown}");
state.verificationCode = "重新发送(${state.initialCountdown})";
} else {
state.timer.cancel();
state.verificationCode = "获取验证码";
state.isGetCodeButtonEnabled = true;
}
});
// 判断是否已经初始化
if (myTimer != null) {
print('Timer is initialized.');
} else {
print('Timer is not initialized.');
}
// 在合适的地方 取消 Timer
myTimer?.cancel();
网友评论