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
Properties
Methods
-
call(
void action()) → void -
Executes
actiononly 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