Throttler class

A utility to enforce a maximum execution frequency for a function.

Useful for scroll handlers, button tap protection, and rate-limited APIs.

final Throttler throttler = Throttler(duration: const Duration(milliseconds: 500));

void onButtonPressed() {
  throttler.run(() => submitPayment());
}

Constructors

Throttler({Duration duration = const Duration(milliseconds: 500)})
Creates a throttler that permits execution at most once every duration.

Properties

duration → Duration
The minimum interval between executions.
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

dispose() → void
Disposes the throttler.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Resets the throttle timer.
run(void action(), {bool trailing = false}) → void
Runs action if duration has elapsed since the last execution.
toString() → String
A string representation of this object.
inherited

Operators

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