JThrottler class
A utility class for throttling actions to limit their execution frequency.
The Throttler class ensures that a given action is executed no more than
once within the specified interval. This is particularly useful for
scenarios like button presses or scroll events where frequent calls could
cause performance issues.
Example Usage
final throttler = Throttler(Duration(seconds: 2));
void handleAction() {
print('Action executed');
}
// Example: Throttle button presses
ElevatedButton(
onPressed: () => throttler.call(handleAction),
child: Text('Throttle Action'),
);
Constructors
- JThrottler(Duration interval)
-
Constructs a
Throttlerwith the specified timeinterval.
Properties
Methods
-
call(
VoidCallback action, {bool immediateCall = true}) → void -
Executes the provided
action, adhering to the throttling interval. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
) → void - Resets the throttler, canceling any pending action and timer.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited