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.
35 lines
638 B
35 lines
638 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;
|
|
print(timer==null);
|
|
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();
|
|
}
|
|
}
|