flutter_event_limiter library
Flutter Event Limiter - Stop spam clicks, fix race conditions, prevent memory leaks.
Features:
- Throttling: Prevent double-clicks with
ThrottledInkWell,Throttler - Debouncing: Auto-cancel search APIs with
AsyncDebouncedTextController,AsyncDebouncer - Universal Builders: Work with ANY widget using
ThrottledBuilder,DebouncedBuilder - Safe setState: Auto-checks
mountedin async operations - Memory safe: All dispose() paths covered
Quick Start:
// 1. Prevent double-clicks
ThrottledInkWell(
onTap: () => submitOrder(),
child: Text('Submit'),
)
// 2. Search API with auto-cancel
AsyncDebouncedTextController(
onChanged: (text) async => await api.search(text),
onSuccess: (results) => setState(() => _results = results),
onLoadingChanged: (loading) => setState(() => _loading = loading),
)
// 3. Universal throttle (works with ANY widget)
ThrottledBuilder(
builder: (context, throttle) {
return FloatingActionButton(
onPressed: throttle(() => saveData()),
child: Icon(Icons.save),
);
},
)
See individual class documentation for detailed usage.
Classes
- AsyncDebouncedBuilder
- Universal async debounce builder that works with ANY widget.
- AsyncDebouncedCallback
- Async debounced callback wrapper with auto-cancel for search/autocomplete.
-
AsyncDebouncedCallbackBuilder<
T> - Enhanced async debounced callback with loading state and error handling.
-
AsyncDebouncedTextController<
T> - Enhanced debounced text controller with loading/error state support for async operations.
- AsyncDebouncer
- Debounce with auto-cancel for async operations (search API, autocomplete).
- AsyncThrottledBuilder
- Universal async throttle builder that works with ANY widget.
- AsyncThrottledCallback
- Async callback wrapper. Locks until Future completes (for form submit).
- AsyncThrottledCallbackBuilder
- Enhanced async callback wrapper with loading state and error handling.
- AsyncThrottler
- Prevents duplicate async operations by locking until Future completes.
- BatchThrottler
- Batch execution utility for throttling/debouncing multiple actions as one.
- CallbackController
- Base class for time-controlled callbacks (Throttler, Debouncer, ThrottleDebouncer).
- ConcurrentAsyncThrottledBuilder
- Advanced async throttled callback builder with concurrency control.
- ConcurrentAsyncThrottler
- Advanced async throttler with concurrency control strategies.
- DebouncedBuilder
- Universal debounce builder that works with ANY widget.
- DebouncedCallback
- Debounced callback wrapper. For search input use DebouncedTextController instead.
- DebouncedTapWidget
- Debounced tap (waits until user stops). Rarely needed - use for auto-save.
- DebouncedTextController
- TextField controller with debounce (default 300ms). Triggers onChanged after user pauses typing.
- Debouncer
- Delays execution until user stops calling for duration (default 300ms).
- HighFrequencyThrottler
- Throttle for high-frequency events (scroll, resize) using DateTime check.
- ThrottledBuilder
- Universal throttle builder that works with ANY widget.
- ThrottledCallback
- QUICK START:
- ThrottleDebouncer
- Combines leading (immediate) + trailing (after pause) execution.
- ThrottledInkWell
- Throttled tap with ripple effect (500ms window).
- ThrottledTapWidget
- Throttled tap without ripple. Use ThrottledInkWell for ripple effect.
- Throttler
- Prevents spam clicks by blocking calls for duration after first execution.
Enums
- ConcurrencyMode
- Execution strategy for concurrent async operations.
Extensions
- ConcurrencyModeExtension on ConcurrencyMode
- Extension methods for ConcurrencyMode to provide readable descriptions.