Skip to content

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

Closed

Description

@matthewalberto

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 a004408 (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

Activity

  1. matthewalberto commented on Nov 20, 2026

    @matthewalberto
    ContributorAuthor

    Fix in #4241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions