Skip to content

brewkits/flutter_debounce_throttle

Repository files navigation

flutter_debounce_throttle

pub package License: MIT Tests Coverage GitHub stars

High-performance, memory-safe, and lifecycle-aware traffic control for Flutter & Dart. Debounce, throttle, rate limiting (Token Bucket), and async concurrency control with Zero Silent Failures.

Debounced Search Anti-Spam Button Async Submit
Search Throttle Submit
Concurrency Replace Hooks Edition Riverpod Integration
Replace Hooks Riverpod

πŸš€ What's New in v2.4.6: The Honest API

Most libraries return void, causing "silent failures" where dropped operations appear to succeed. This library introduces ThrottlerResult and DebounceResult to ensure your code handles every outcome.

// βœ… Honest API β€” both branches required at compile time
final result = await throttler.call(() async => await processPayment(order));

result.when(
  onExecuted: () => showSuccessDialog(),  // Safe: payment actually ran
  onDropped:  () => showError('Busy!'),  // Handled: user knows it failed
);

Quick Start

Anti-spam button β€” 1 line:

ThrottledInkWell(onTap: () => processPayment(), child: Text('Pay \$99'))

Debounced search:

final debouncer = Debouncer(duration: 300.ms);
TextField(onChanged: (s) => debouncer(() => search(s)))

State management (Provider, Riverpod, GetX, Bloc):

class SearchController with ChangeNotifier, EventLimiterMixin {
  void onSearch(String text) {
    debounce('search', () async {
      _results = await api.search(text);
      notifyListeners();
    });
  }

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

Which Package?

You are building... Install
Flutter app flutter_debounce_throttle
Flutter app + flutter_hooks flutter_debounce_throttle_hooks
Flutter app + Riverpod flutter_debounce_throttle_riverpod
Dart server / CLI / Serverpod dart_debounce_throttle

Why This Library?

Capability This Library easy_debounce Manual Timer
Honest API (No Silent Failures) βœ… ❌ ❌
Memory Safe (Auto-dispose) βœ… ❌ ❌ Leaky
Async & Future Support βœ… ❌ ❌
Race Condition Control (4 modes) βœ… ❌ ❌
Ready-to-use Widgets βœ… ❌ ❌
Distributed Rate Limiting βœ… ❌ ❌
Zero External Dependencies 0 0 0

Quality & Reliability

570+ tests Unit, widget, integration, security, performance & stress tests
98% coverage Every branch and edge case verified
Security First DoS protection and memory exhaustion guards built-in
Type-safe Full generics, no dynamic, compile-time safety with when()
Memory-safe Verified with Flutter LeakTracker to ensure zero leaks

Documentation

FAQ Common questions
API Reference Complete class/method docs
Best Practices Patterns & recommendations
Migration Guide From easy_debounce, rxdart, manual Timer
Example App Comprehensive interactive demos

Made with craftsmanship by Brewkits