dart_debounce_throttle 2.1.1
dart_debounce_throttle: ^2.1.1 copied to clipboard
Pure Dart debounce, throttle, and rate limiting. Zero dependencies, works everywhere - Mobile, Web, Desktop, Server, CLI.
2.1.1 #
Documentation - Enhanced README and improved safety warnings.
- Add comprehensive comparison vs rxdart, easy_debounce, manual Timer
- Add "Why Choose This Over Alternatives" section to README
- Improve documentation for ConcurrentAsyncThrottler maxQueueSize warning
- Add memory guard test cases
- Create ROADMAP.md for v2.2.0 features
2.1.0 #
Feature - Stream extensions for rxdart-style debounce and throttle.
- Add
.debounce()extension method for streams - Add
.throttle()extension method for streams - Support both single-subscription and broadcast streams
- Zero additional dependencies
Example:
searchController.stream
.debounce(Duration(milliseconds: 300))
.listen((query) => performSearch(query));
2.0.0+1 #
Fix - Update repository URL for pub.dev validation.
- Fix repository URL to point to package subdirectory
- Improves pub.dev score by passing repository validation check
2.0.0 #
BREAKING CHANGE - Package renamed to follow Dart naming conventions.
What Changed #
The package has been renamed from flutter_debounce_throttle_core to dart_debounce_throttle.
Pure Dart packages should not have the flutter_ prefix, as this package has zero Flutter dependencies and works in any Dart environment (server, CLI, web, mobile).
Migration Guide #
1. Update pubspec.yaml:
# Before
dependencies:
flutter_debounce_throttle_core: ^1.1.0
# After
dependencies:
dart_debounce_throttle: ^2.0.0
2. Update imports:
// Before
import 'package:flutter_debounce_throttle_core/flutter_debounce_throttle_core.dart';
// After
import 'package:dart_debounce_throttle/dart_debounce_throttle.dart';
3. Run pub get:
dart pub get # or flutter pub get
No API Changes #
All classes, methods, and functionality remain exactly the same. Only the package name and import path have changed.
1.1.1 #
Documentation - Enhanced README for better pub.dev presentation.
- Improved package description and badges
- Added server-problem examples (API cost, DB overload, DDoS)
- Added comparison table vs manual implementation
- Better Token Bucket and Batch Processing documentation
1.1.0 #
Enterprise Features - Advanced event limiting capabilities for production workloads.
New Classes #
RateLimiter- Token Bucket algorithm for burst-capable rate limiting- Allow burst of N requests then throttle to sustained rate
- Perfect for API rate limiting, game input, server protection
tryAcquire(),call(),callAsync(),availableTokens,timeUntilNextToken
New Extension Methods #
- Duration shortcuts:
300.ms,2.seconds,5.minutes,1.hours - Callback extensions:
myFunc.debounced(300.ms),myFunc.throttled(500.ms)
Enhanced Debouncer #
- Leading edge:
leading: true- Execute immediately on first call - Trailing edge:
trailing: true- Execute after pause (default) - Both edges: Combine for lodash-style behavior
final debouncer = Debouncer(
duration: Duration(milliseconds: 300),
leading: true, // Execute immediately
trailing: true, // Also execute after pause
);
Enhanced BatchThrottler #
maxBatchSize- Prevent OOM by limiting batch sizeBatchOverflowStrategy- Choose behavior when batch is full:dropOldest- Remove oldest action to make roomdropNewest- Reject new actionflushAndAdd- Immediately flush batch, then add new action
Enhanced ConcurrentAsyncThrottler #
maxQueueSize- Limit queue size in enqueue modeQueueOverflowStrategy- Choose behavior when queue is full:dropNewest- Reject new calldropOldest- Remove oldest queued call
All new features are backward compatible with null defaults.
1.0.1 #
- Fix package description length to meet pub.dev requirements (60-180 chars)
- Add example demonstrating debounce and throttle usage
- Update meta dependency to ^1.16.0 for better Flutter SDK compatibility
1.0.0 #
Enterprise Edition - The Safe, Unified & Universal Event Limiter for Flutter & Dart.
Complete rewrite with modern API, monorepo architecture, and full server-side support. Ready for production use.
🎯 Highlights #
- Modern Callable Class API - Call limiters like functions:
debouncer(() => ...) - Pure Dart Core - Works on Dart servers (Serverpod, Dart Frog, etc.)
- Monorepo Structure - Separate packages for core, flutter, and hooks
- Zero Dependencies - No external dependencies in core package
- ID-based Limiting - Multiple independent limiters with string IDs
- Type-safe & Memory-safe - Generic types, auto-dispose, mounted checks
- 143+ Tests - Comprehensive test coverage
- Backward Compatible - Old APIs still work with deprecation notices
🏗️ Architecture #
Monorepo Packages
flutter_debounce_throttle_core- Pure Dart core (no Flutter deps)flutter_debounce_throttle- Flutter integration (widgets + mixin)flutter_debounce_throttle_hooks- Optional Flutter Hooks support
Import Strategy
// Flutter apps
import 'package:flutter_debounce_throttle/flutter_debounce_throttle.dart';
// Hooks (optional)
import 'package:flutter_debounce_throttle_hooks/flutter_debounce_throttle_hooks.dart';
// Pure Dart (Server/CLI)
import 'package:flutter_debounce_throttle_core/flutter_debounce_throttle_core.dart';
✨ New Features #
1. Callable Class Pattern
Classes can now be called like functions (Dart convention):
// AsyncDebouncer
final debouncer = AsyncDebouncer(duration: Duration(milliseconds: 300));
final result = await debouncer(() async => api.search(query));
// BatchThrottler
final batcher = BatchThrottler(duration: Duration(milliseconds: 100));
batcher(() => save('item1'));
batcher(() => save('item2'));
Old API (deprecated but still works):
AsyncDebouncer.run()→ Usecall()or callable syntaxBatchThrottler.add()→ Usecall()or callable syntax
2. Improved Mixin API
Cleaner method names for EventLimiterMixin:
class MyController with EventLimiterMixin {
void dispose() {
cancel('search'); // NEW: Cancel specific limiter
cancelAll(); // NEW: Cancel all limiters
super.dispose();
}
}
Old API (deprecated but still works):
cancelLimiter(id)→ Usecancel(id)cancelAllLimiters()→ UsecancelAll()
3. Widget Rename
Better naming for search/query widget:
DebouncedQueryBuilder<List<User>>( // NEW name
onQuery: (text) async => await search(text), // NEW parameter name
onResult: (users) => updateUI(users), // NEW parameter name
builder: (context, search, isLoading) => TextField(onChanged: search),
)
Old API (deprecated but still works):
AsyncDebouncedCallbackBuilder→ UseDebouncedQueryBuilderonChanged→ UseonQueryonSuccess→ UseonResult
4. Environment-aware Logging
void main() {
DebounceThrottleConfig.init(
enableDebugLog: true,
logLevel: LogLevel.debug,
logHandler: (level, message, name, timestamp) {
print('[$level] $message');
},
);
}
// Instance-level debug mode
final debouncer = Debouncer(
debugMode: true,
name: 'SearchDebouncer',
);
// Output: [SearchDebouncer] Debounce executed after 305ms
5. Server-Side Support
Pure Dart Core works on servers without Flutter:
// example/server_demo/server_example.dart
import 'package:flutter_debounce_throttle_core/flutter_debounce_throttle_core.dart';
class LogBatchingService {
final _debouncer = Debouncer(duration: Duration(seconds: 1));
void log(String message) {
_pendingLogs.add(message);
_debouncer(() {
writeToDB(_pendingLogs);
_pendingLogs.clear();
});
}
}
Run with: dart run example/server_demo/server_example.dart
📦 Core Limiters (Pure Dart) #
All limiters work in both Flutter and pure Dart environments:
Throttler- Execute immediately, block subsequent calls for durationDebouncer- Delay execution until pause in callsAsyncDebouncer- Async debounce with cancellation support (NEW: callable)AsyncThrottler- Lock-based async throttle with timeoutHighFrequencyThrottler- Optimized for 60fps events (scroll, mouse)BatchThrottler- Batch multiple operations (NEW: callable)ConcurrentAsyncThrottler- 4 concurrency modes (drop, enqueue, replace, keepLatest)ThrottleDebouncer- Combined leading + trailing edge execution
🎨 Flutter Widgets #
ThrottledBuilder- Universal throttle wrapper widgetThrottledInkWell- Material button with built-in throttleDebouncedBuilder- Debounce wrapper widgetDebouncedQueryBuilder- Async query with loading state (NEW: renamed from AsyncDebouncedCallbackBuilder)AsyncThrottledBuilder- Async throttle with loading stateAsyncDebouncedBuilder- Async debounce with loading stateConcurrentAsyncThrottledBuilder- Concurrency modes widget
🌊 Stream Listeners #
StreamSafeListener- Auto-cancel stream subscription on disposeStreamDebounceListener- Debounce stream eventsStreamThrottleListener- Throttle stream events
⌨️ Text Controllers #
DebouncedTextController- TextField controller with debouncingAsyncDebouncedTextController- Async search controller with loading state
🎛️ State Management #
EventLimiterMixin- ID-based limiters for any controller- Works with Provider, GetX, Bloc, MobX, Riverpod
- NEW:
cancel(id)andcancelAll()methods - Methods:
debounce(),throttle(),debounceAsync(),throttleAsync()
🪝 Flutter Hooks (Optional Package) #
useDebouncer- Hook for Debouncer instanceuseThrottler- Hook for Throttler instanceuseAsyncDebouncer- Hook for AsyncDebouncer instanceuseAsyncThrottler- Hook for AsyncThrottler instanceuseDebouncedCallback- Hook for debounced callbackuseThrottledCallback- Hook for throttled callbackuseDebouncedValue- Hook for debounced valueuseThrottledValue- Hook for throttled value
⚙️ Configuration #
DebounceThrottleConfig.init(
enableDebugLog: true,
logLevel: LogLevel.debug,
logHandler: (level, message, name, timestamp) {
// Custom logging
},
);
Log Levels: none, error, warning, info, debug
📚 Documentation #
- Migration Guide - Migrate from easy_debounce, manual Timer, rxdart
- Master Plan - Complete project documentation
- Server Demo - Pure Dart examples
- Example App - 5 interactive demos
- 143+ Tests - Comprehensive test coverage
🔄 Migration from Old API #
All old APIs still work but are deprecated. Update at your convenience:
// AsyncDebouncer
await debouncer.run(() async => ...) // Old (deprecated)
await debouncer(() async => ...) // New (callable)
// BatchThrottler
batcher.add(() => ...) // Old (deprecated)
batcher(() => ...) // New (callable)
// EventLimiterMixin
cancelLimiter('id') // Old (deprecated)
cancel('id') // New
cancelAllLimiters() // Old (deprecated)
cancelAll() // New
// Widgets
AsyncDebouncedCallbackBuilder // Old (deprecated)
DebouncedQueryBuilder // New
See Migration Guide for detailed examples.
🎯 Quality Metrics #
- ✅ 143+ tests - All passing
- ✅ Zero dependencies - Core package has no external deps
- ✅ Type-safe - Generic types, no dynamic
- ✅ Memory-safe - Auto-dispose, mounted checks
- ✅ Static analysis clean - No issues
- ✅ Server-ready - Pure Dart Core proven working
📊 Package Sizes #
flutter_debounce_throttle_core- ~30KB (pure Dart)flutter_debounce_throttle- ~50KB (includes widgets)flutter_debounce_throttle_hooks- ~10KB (hooks only)
🙏 Acknowledgments #
This release represents a complete Enterprise Edition rewrite with modern APIs, comprehensive testing, and production-grade architecture. Special thanks to all contributors and early adopters.