如何在颤振上使用 TimerTask?

Ger*_*jcr 1 timertask flutter

我想创建一个每 x 秒运行一次的函数..

在java中有

TimerTask
Run Code Online (Sandbox Code Playgroud)

但颤振是什么?

Cop*_*oad 5

import 'dart:async'; // import this 
Run Code Online (Sandbox Code Playgroud)

并使用名为构造函数的Timerperiodic

Timer.periodic(Duration(seconds: 1), (timer) {
  // this block runs every second
  // and when you want to stop it, simply call `timer.cancel();` here
});
Run Code Online (Sandbox Code Playgroud)