Timer with tickCount stays finished after start() or reset()

未关闭 适合新手
#4,240 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@matthewalberto 已经在做这个了。

开始于 2026年11月20日。

  • #4241 来自 @matthewalberto —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
dart, flutter
领域
backend

调研方向

从 Timer 的实现及其测试入手,找到 reset()、start()、stop() 和 _callTicker;issue 指出了 tick 计数器以及达到上限时的行为。用 tickCount: 2 重现示例,然后检查重启和重置是否允许再 tick 两次,以及计时器在达到上限后是否报告 finished。

由索引模型根据 Issue 内容生成。

描述

What happened?

A Timer (or TimerComponent) with tickCount never resets its tick counter. start(), stop() and reset() only set current back to 0, so once the timer has ticked tickCount times:

  • finished is still true right after start(), even though the timer is running again. A TimerComponent with removeOnFinish: true is removed on its next update.
  • The restarted timer ticks once and stops, instead of ticking tickCount times again.

reset() part way through has the same problem: the ticks counted before the reset still count towards the limit.

What do you expect?

start() starts the timer from 0, as its docs say, so it should tick tickCount times again and not be finished until it has. reset() should also reset the ticks.

How can we reproduce this?
var count = 0;
final timer = Timer(
  period: 1,
  repeat: true,
  tickCount: 2,
  onTick: () => count++,
);
timer.update(1.1);
timer.update(1.1);
print(count); // 2
print(timer.finished); // true

timer.start();
print(timer.finished); // true, expected false
timer.update(1.1);
timer.update(1.1);
print(count); // 3, expected 4
What steps should take to fix this?

Reset _currentTick in Timer.reset() (which start() and stop() call). When the tick limit is reached, _callTicker calls stop() today; it would need to set _current to 0 and pause instead, so that the timer still reports finished afterwards.

Affected platforms

All

Other information

Flame main at a0044089 (flame 2.0.0-dev.1), Flutter 3.47.9 stable. tickCount was added in #3552.

Are you interested in working on a PR for this?
  • I want to work on this
主要语言
Dart
星标
10.8k
派生
1.1k
平均合并
2 天 4 小时
30 天内合并 PR
61

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

flame-engine/flame 的其他 Issue

查看 flame-engine/flame 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。