You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/provider/clock_timer_provider.dart

34 lines
614 B

import 'dart:async';
import 'package:flutter/material.dart';
class ClockTimerProvider extends ChangeNotifier {
///登录页验证码计时器
int second = 60;
bool timerStart = false;
Timer? timer;
void startTimer() {
timerStart = true;
if (timer != null) {
return;
}
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();
}
}