如果我为3个不同的功能运行3个不同的计时器,我该如何取消特定的计时器。
例
const oneSec = const Duration(seconds: 60);
new Timer.periodic(
oneSec,
(Timer t) async =>
await appLoggerRepository.putAppLogOnServer(jobName));
const oneSec = const Duration(seconds: 60);
new Timer.periodic(
oneSec,
(Timer t) async =>
await appLoggerRepository.uploadOrder(jobName));
const oneSec = const Duration(seconds: 60);
new Timer.periodic(
oneSec,
(Timer t) async =>
await appLoggerRepository.checkdevice(jobName));
~~
最佳答案
您必须创建一个计时器变量
Timer logTimer = Timer.periodic( //no need for the new keyword
oneSec,
(Timer t) async =>
await appLoggerRepository.putAppLogOnServer(jobName));
//to cancel call cancel()
logTimer.cancel();
关于flutter - 如何取消特定计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62450262/