Throttle class final

Limits the execution frequency of a function to at most once per interval.

The Throttle pattern is useful when you want to limit how often an action happens, even if events occur frequently. Unlike debouncing (which waits for inactivity), throttling allows periodic execution.

Use cases:

  • Scroll events: fire handler at most once per 100ms while scrolling
  • Mouse move: limit position updates while tracking mouse movement
  • Button clicks: prevent rapid-fire clicks on expensive operations
  • API calls: rate-limit requests during rapid user interactions

Example:

final throttle = Throttle(Duration(milliseconds: 100));

// In scroll listener
throttle(() => updateUI());
// First call executes immediately
// Subsequent calls within 100ms are ignored
// Call after 100ms executes again

Note: This throttle uses > for interval comparison, meaning it requires strictly more than the interval time to have passed before allowing another execution. Standard behavior would use >= to allow execution at the exact interval boundary. Adjust if needed for your use case.

Annotations
  • @experimental

Constructors

Throttle(Duration interval)
Creates a throttle with the given interval.

Properties

hashCode int
The hash code for this object.
no setterinherited
interval Duration
The minimum time between action executions.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(void action()) → void
Executes action only if enough time has passed since the last execution.
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