Throttle class

A simple class for throttling function execution.

class _MyHomePageState extends State<MyHomePage> {
  final Throttle _throttler = Throttle(milliseconds: 300);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Throttle Example'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            _throttler.run(_onButtonPressed);
          },
          child: Text('Press me'),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _throttler.dispose();
    super.dispose();
  }

  void _onButtonPressed() {
    print("Button pressed!");
  }
}

Constructors

Throttle({int milliseconds = kDefaultThrottlerDuration})
A simple class for throttling function execution.

Properties

hashCode int
The hash code for this object.
no setterinherited
milliseconds int
The delay in milliseconds.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → void
Disposes the timer if it is active.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run(VoidCallback action) → void
Runs the action after milliseconds delay.
toString() String
A string representation of this object.
inherited

Operators

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