Repository navigation
fix: Reset the tick count of a Timer on reset and start - #4241
Merged
ufrshubham merged 3 commits intoNov 21, 2026
Merged
Conversation
Timer.reset, and so start and stop, now also reset the ticks counted towards tickCount. Before, a Timer with tickCount stayed finished after start, and ticked only once more before stopping again. When the tick limit is reached the timer now sets current to 0 and pauses instead of calling stop, so it still reports finished.
1 task done
ufrshubham
reviewed
Nov 20, 2026
ufrshubham
left a comment
Member
There was a problem hiding this comment.
Thanks for this, and for the thorough testing notes in the description! The core change is right. I found one off-by-one when the timer is restarted from its own onTick, and I'd like the new stop() behaviour documented. Details are in the inline comments.
The tick is now counted before onTick runs, so start() or reset() called from onTick restarts the tick count instead of being undone straight away. Adds tests for start() and reset() from onTick, and for stop() after the tick limit, and documents that start(), reset() and stop() reset the tick count.
matthewalberto
added a commit
to matthewalberto/matthewalberto
that referenced
this pull request
Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Timer.reset()now also resets the number of ticks counted towardstickCount, sostart()andstop()do too, since they call it. Before, aTimerwithtickCountthat had ticked its limit stayedfinishedafterstart()(aTimerComponentwithremoveOnFinishwas removed on its next update), and it ticked once more and stopped instead of tickingtickCounttimes again. Areset()part way through also kept the earlier ticks.When the limit is reached,
_callTickerused to callstop(). Sincestop()now clears the ticks, that would make the timer report not finished right after finishing, so it setscurrentto 0 and pauses instead, which is whatstop()did there before. One behaviour change:stop()on a timer that has used up its ticks now leaves it notfinished, the same asstop()already does for a non-repeating timer.TimerComponentandSpawnComponentdo not depend on the old behaviour.After review, the tick is counted before
onTickruns, sostart()orreset()called fromonTickrestarts the count instead of being undone straight away. ThetickCountnote indoc/flame/other/util.mdnow says thatstart()andreset()restart the tick count and thatstop()resets it too.Testing: six new tests in
test/timer_test.dart(restart withstart(),reset()part way through,start()fromonTickwithtickCount: 3andtickCount: 1,reset()fromonTick, andstop()after the limit). The first two fail onmain, the threeonTickones fail on the first commit of this PR, and all pass with the fix. I also broke each part of the original fix on its own (ticks not reset,stop()called again at the limit, no pause at the limit,currentnot set to 0 at the limit), and a test failed for each. The fullpackages/flamesuite on Windows: 2536 passed onmainand 2542 with this PR, with the same 10 failures on both, by name (8 inassets_cache_test.dart, 1 intext_layouting_test.dartand 1 inskills_lint_test.dart, which fail on Windows on untouchedmain).dart formatandflutter analyzeare clean for the changed files. Not tested: on Linux or macOS, or in a running game.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #4240