You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter stop_watch_timer包onExecute未定义报错求助及代码替代方案

解决Flutter stop_watch_timer包构建报错问题

问题原因

stop_watch_timer 3.1.0+4版本已移除onExecute这个API,原代码中通过time.stopWatchTimer.onExecute.add(StopWatchExecute.start)启动计时器的方式不再兼容。

替代实现方案

直接调用StopWatchTimer实例的start()方法启动计时器,修改后的代码如下:

@override
void initState() {
  super.initState();
  getCurrentQuestion();
  // 直接调用start方法启动计时器
  time.stopWatchTimer.start();
}

扩展控制方法

如果需要对计时器进行更多操作,可直接调用对应实例方法:

  • 暂停计时器:time.stopWatchTimer.stop()
  • 重置计时器:time.stopWatchTimer.reset()
  • 重置后重新启动:time.stopWatchTimer.onResetTimer.then((_) => time.stopWatchTimer.start())

内容的提问来源于stack exchange,提问作者Shamanth R S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 13:13:44