Flutter 如何取消特定计时器?

Flutter 如何取消特定计时器?,flutter,dart,timer,cancellation,periodic-task,Flutter,Dart,Timer,Cancellation,Periodic Task,如果我为3个不同的功能运行3个不同的计时器,如何取消特定的计时器 范例 const oneSec = const Duration(seconds: 60); new Timer.periodic( oneSec, (Timer t) async => await appLoggerRepository.putAppLogOnServer(jobName)); const oneSec = c

如果我为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//不需要新关键字 一秒, 计时器t异步=> 等待appLoggerRepository.putAppLogOnServerjobName; //取消呼叫取消 logTimer.cancel;