safe_debouncer 0.1.1 copy "safe_debouncer: ^0.1.1" to clipboard
safe_debouncer: ^0.1.1 copied to clipboard

A safe, async-aware debouncer for Dart & Flutter that prevents overlapping executions and timer leaks.

safe_debouncer #

A safe, async-aware debouncer for Dart & Flutter that prevents overlapping executions, timer leaks, and repeated boilerplate code.

safe_debouncer is a logic-only utility designed to handle one of the most common pain points in app development: debouncing actions correctly.


✨ Why safe_debouncer? #

Most debounce implementations:

  • leak Timers
  • break on rebuilds
  • don’t handle async callbacks
  • allow overlapping executions
  • get re-written differently in every project

safe_debouncer solves this once and for all.


πŸš€ Features #

  • βœ… Supports sync & async callbacks
  • βœ… Prevents overlapping executions
  • βœ… Safe cancellation and disposal
  • βœ… Rebuild-safe
  • βœ… Key-based debouncing for multiple streams (SafeDebouncerMap)
  • βœ… Individual debouncer instances (SafeDebouncer)
  • βœ… Pure Dart (no Flutter dependency)
  • βœ… Tiny, focused API

πŸ“¦ Installation #

Add to your pubspec.yaml:

dependencies:
  safe_debouncer: ^0.0.1

πŸ“š Usage #

Basic Usage #

import 'package:safe_debouncer/safe_debouncer.dart';

void main() {
  final debouncer = SafeDebouncer(Duration(milliseconds: 500));

  debouncer.call(() {
    print('Debounced action executed!');
  });
}

Async Callbacks #

import 'package:safe_debouncer/safe_debouncer.dart';

void main() async {
  final debouncer = SafeDebouncer(Duration(milliseconds: 500));

  await debouncer.callAsync(() async {
    print('Debounced async action executed!');
  });
}

Key-based Debouncing #

import 'package:safe_debouncer/safe_debouncer.dart';

void main() {
  final debouncerMap = SafeDebouncerMap(Duration(milliseconds: 500));

  debouncerMap.call('key1', () {
    print('Debounced action executed for key1!');
  });

  debouncerMap.call('key2', () {
    print('Debounced action executed for key2!');
  });
}

πŸ“– API Reference #

SafeDebouncer #

  • SafeDebouncer(Duration duration): Creates a new SafeDebouncer instance with the specified duration.
  • call(VoidCallback callback): Calls the callback after the specified duration.
  • callAsync(Future<void> Function() callback): Calls the callback after the specified duration and returns a Future that completes when the callback is executed.

SafeDebouncerMap #

  • SafeDebouncerMap(Duration duration): Creates a new SafeDebouncerMap instance with the specified duration.
  • call(String key, VoidCallback callback): Calls the callback after the specified duration for the specified key.
  • callAsync(String key, Future<void> Function() callback): Calls the callback after the specified duration for the specified key and returns a Future that completes when the callback is executed.
0
likes
160
points
148
downloads

Publisher

unverified uploader

Weekly Downloads

A safe, async-aware debouncer for Dart & Flutter that prevents overlapping executions and timer leaks.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on safe_debouncer