PrfCooldown class

A utility for managing cooldown logic using persisted DateTime and Activation Count.

Stores:

  • the last activation time (<prefix>_cd_date_time)
  • the total activation count (<prefix>_cd_count)

Example:

final cooldown = PrfCooldown('daily_reward', duration: Duration(hours: 24));
if (!await cooldown.isCooldownActive()) {
  await cooldown.activateCooldown();
}

Constructors

PrfCooldown.new(String prefix, {required Duration duration})
Creates a new cooldown with the specified prefix and duration.

Properties

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

Methods

activateCooldown() Future<void>
Activates the cooldown using the default duration.
anyStateExists() Future<bool>
Checks if any values related to this cooldown exist in persistent storage.
completeReset() Future<void>
Completely resets the cooldown and counter.
getActivationCount() Future<int>
Returns the number of times the cooldown has been activated.
getEndTime() Future<DateTime?>
Returns the timestamp when the cooldown will expire, or null if not active.
getLastActivationTime() Future<DateTime?>
Returns the timestamp of the last activation, or null if never activated.
isCooldownActive() Future<bool>
Returns true if the cooldown is still active.
isExpired() Future<bool>
Returns true if the cooldown has expired or was never activated.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
percentRemaining() Future<double>
Returns the percentage of cooldown time remaining as a value between 0.0 and 1.0.
removeAll() Future<void>
Removes all saved values and duration from persistent storage.
reset() Future<void>
Resets the cooldown by clearing the activation timestamp.
secondsRemaining() Future<int>
Returns the remaining cooldown time in seconds.
timeRemaining() Future<Duration>
Gets the remaining time until the cooldown ends.
toString() String
A string representation of this object.
inherited
tryActivate() Future<bool>
Attempts to activate the cooldown only if it is not currently active.
whenExpires() Future<void>
Completes when the cooldown expires.

Operators

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