StreakCalculator class

Calculates streaks from a list of DateTime values.

Useful for habit trackers, attendance systems, workout apps, and daily check-ins.

final dates = [
  DateTime(2024, 6, 1),
  DateTime(2024, 6, 2),
  DateTime(2024, 6, 3),
  DateTime(2024, 6, 5), // gap on 4th
  DateTime(2024, 6, 6),
];

StreakCalculator.currentStreak(dates)  // 2
StreakCalculator.longestStreak(dates)  // 3
StreakCalculator.isTodayCompleted(dates) // false

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

allStreaks(List<DateTime> dates) List<List<DateTime>>
Returns all streak runs as a list of lists.
completionRate(List<DateTime> dates, {required DateTime start, required DateTime end}) double
Returns completion rate as percentage (0.0 – 1.0) between start and end dates.
currentStreak(List<DateTime> dates) int
Returns the current active streak count.
isTodayCompleted(List<DateTime> dates) bool
Returns true if today is in dates.
lastCompletedDate(List<DateTime> dates) DateTime?
Returns the last completed date or null.
longestStreak(List<DateTime> dates) int
Returns the longest streak ever in dates.
missedDays(List<DateTime> dates, {required DateTime start}) int
Returns number of days missed between start and today.
totalCompleted(List<DateTime> dates) int
Returns total number of completed days in dates.