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

Đang mở Phù hợp với người mới
#4,240 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@matthewalberto đang làm issue này rồi.

Từ ngày 20/11/2026.

  • #4241 của @matthewalberto — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
dart, flutter
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với phần triển khai Timer và các bài kiểm thử, tìm reset(), start(), stop() và _callTicker; issue nêu bộ đếm tick và hành vi khi đạt đến giới hạn. Tái hiện ví dụ với tickCount: 2, sau đó kiểm tra rằng việc khởi động lại và đặt lại cho phép thêm hai tick, đồng thời bộ hẹn giờ báo finished sau khi đạt giới hạn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Dart
Star
10.8k
Fork
1.1k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
61

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của flame-engine/flame

Tất cả issue của flame-engine/flame

Issue tương tự

Thêm issue về Dart

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.