我想创建一个每 x 秒运行一次的函数..
在java中有
TimerTask
Run Code Online (Sandbox Code Playgroud)
但颤振是什么?
import 'dart:async'; // import this
Run Code Online (Sandbox Code Playgroud)
并使用名为构造函数的Timer类periodic。
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)