track 1.1.3
track: ^1.1.3 copied to clipboard
Easily track streaks, counters, history, and records. Effortless persistent trackers with no manual timers or storage, just define and go.
import 'package:flutter/widgets.dart';
import 'package:track/track.dart';
Future<void> main() async {
// โ
Create a daily streak tracker
final streak = StreakTracker(
'daily_exercise',
period: TimePeriod.daily,
recordsHistory: 3,
);
// โก Bump the streak (mark today as completed)
await streak.bump();
debugPrint('Streak bumped!');
// ๐ Get the current streak count
final current = await streak.currentStreak();
debugPrint('Current streak: $current');
// โ Check if the streak is broken
final isBroken = await streak.isStreakBroken();
debugPrint('Is streak broken? $isBroken');
// ๐
Check when the streak will break next
final nextReset = await streak.nextResetTime();
debugPrint('Next reset time: $nextReset');
// ๐ Get percent of time remaining before streak breaks
final percentLeft = await streak.percentRemaining();
debugPrint(
'Percent of time remaining: ${(percentLeft! * 100).toStringAsFixed(2)}%');
// โฑ Check how long ago the last bump happened
final age = await streak.streakAge();
debugPrint('Time since last bump: ${age?.inHours} hours');
// ๐ Get best streak ever
final best = await streak.records.getBestRecord();
debugPrint('Best streak ever: $best');
// ๐งฏ Reset the streak
await streak.reset();
debugPrint('Streak reset!');
// ๐งช Debug helpers
final hasData = await streak.hasState();
debugPrint('Has saved state? $hasData');
await streak.clear();
debugPrint('State cleared!');
}