Как мне отменить указанный таймер c? - PullRequest
0 голосов
/ 18 июня 2020

Если я использую 3 разных таймера для 3 разных функций, как мне отменить указанный c один.

Пример

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));

~~

1 Ответ

1 голос
/ 18 июня 2020

Вы должны создать переменную таймера

Timer logTimer = Timer.periodic( //no need for the new keyword
            oneSec,
            (Timer t) async =>
                await appLoggerRepository.putAppLogOnServer(jobName));

//to cancel call cancel()
logTimer.cancel();
...