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
相关产品推荐
相关产品推荐

