【发布时间】:2021-05-01 21:48:30
【问题描述】:
我的 Flutter 应用中有一个周期性计时器,它每 x 秒更改一次页面上的一些值:
periodicTimer = new Timer.periodic(Duration(seconds: timer), (Timer t) {
setState(() {
if (globals.selectedBottomNav == 0) {
nextKey();
} else {
nextCircleKey();
}
});
});
但是,我需要能够在更短的时间内执行另一项操作。因此,例如,如果我的 timer 变量设置为 5 秒,我需要能够每 5 秒运行一次 setState,但在每个定时循环的 3 秒后,我想运行一些其他代码。
对我如何实现这一目标有任何帮助吗?我尝试了各种嵌套的 Timer 和 Timer.periodic 选项,但得到了奇怪的结果。
谢谢
【问题讨论】: