zeba_academy_debouncer

Pub Version Flutter Dart License: GPL v3 Platform

A lightweight, dependency-free Flutter package that provides debouncing, throttling, timer-based execution control, cancelable callbacks, and search optimization helpers.

Perfect for search bars, API requests, button click protection, form validation, and other performance-sensitive tasks.


✨ Features

  • šŸš€ Debounce function execution
  • ⚔ Throttle repeated actions
  • ā± Timer-based execution control
  • āŒ Cancel scheduled callbacks
  • šŸ”„ Immediate callback execution (Flush)
  • šŸ” Search optimization helper
  • 🌐 Async callback support
  • šŸ’™ Zero external dependencies
  • āœ… Null Safety
  • šŸ“± Flutter & Dart compatible

Platform Support

Platform Supported
Android āœ…
iOS āœ…
Web āœ…
Windows āœ…
macOS āœ…
Linux āœ…

Installation

Add the package to your pubspec.yaml

dependencies:
  zeba_academy_debouncer: ^1.0.0

Then run

flutter pub get

Import

import 'package:zeba_academy_debouncer/zeba_academy_debouncer.dart';

Debouncer

Execute a callback only after a specified delay.

final debouncer = Debouncer(
  delay: const Duration(milliseconds: 500),
);

TextField(
  onChanged: (value) {
    debouncer.run(() {
      print(value);
    });
  },
);

Async Debouncer

final debouncer = Debouncer(
  delay: const Duration(milliseconds: 500),
);

debouncer.runAsync(() async {
  await fetchUsers();
});

Cancel Pending Callback

debouncer.cancel();

Dispose

debouncer.dispose();

Throttle

Prevent repeated execution within a fixed duration.

final throttle = Throttle(
  duration: const Duration(seconds: 2),
);

ElevatedButton(
  onPressed: () {
    throttle.run(() {
      print("Clicked");
    });
  },
  child: const Text("Submit"),
);

Execution Controller

Schedule a callback.

final controller = ExecutionController();

controller.schedule(
  delay: const Duration(seconds: 2),
  callback: () {
    print("Executed");
  },
);

Cancel Scheduled Execution

controller.cancel();

Execute Immediately

controller.flush(() {
  print("Executed instantly");
});

Search Debouncer

Perfect for search bars.

final search = SearchDebouncer();

TextField(
  onChanged: (value) {
    search.search(
      keyword: value,
      onSearch: (query) {
        print(query);
      },
    );
  },
);

API Search Example

final debouncer = Debouncer(
  delay: const Duration(milliseconds: 600),
);

void searchUsers(String keyword) {
  debouncer.run(() async {
    await api.search(keyword);
  });
}

Form Validation

debouncer.run(() {
  validateEmail(emailController.text);
});

Prevent Double Click

final throttle = Throttle(
  duration: const Duration(seconds: 1),
);

throttle.run(() {
  submitForm();
});

Public API

Debouncer

Method Description
run() Debounce callback
runAsync() Debounce async callback
cancel() Cancel callback
dispose() Dispose resources
isRunning Timer status

Throttle

Method Description
run() Execute once during interval
isReady Current availability

ExecutionController

Method Description
schedule() Schedule callback
cancel() Cancel execution
flush() Execute immediately
dispose() Dispose controller
isActive Timer status

SearchDebouncer

Method Description
search() Debounced search
cancel() Cancel search
dispose() Dispose helper

Why Use This Package?

  • Improves application responsiveness
  • Prevents excessive API requests
  • Protects against accidental double taps
  • Simplifies timer management
  • Optimizes search functionality
  • Lightweight and dependency-free
  • Easy integration with Flutter projects

Roadmap

Future releases may include:

  • Leading edge debounce
  • Trailing edge debounce
  • Max wait duration
  • Stream extensions
  • Grouped debouncers
  • Pause and resume support
  • Widget extensions
  • Riverpod helpers
  • BLoC helpers
  • GetX helpers

Contributing

Contributions, feature requests, bug reports, and pull requests are welcome.

Please open an issue before submitting major changes.


License

This project is licensed under the GNU General Public License v3.0 (GPL-3.0).

See the LICENSE file for details.


About Me

✨ I’m Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects.

You can learn more about me and my work at https://sufyanism.com/ or connect with me on LinkedIn:

https://www.linkedin.com/in/sufyanism


Your all-in-one learning hub!

šŸš€ Explore courses and resources in coding, tech, and development at Zeba Academy.

Empower yourself with practical skills through curated tutorials, real-world projects, and hands-on experience.

🌐 Website

https://zeba.academy

šŸ’» Coding Platform

https://code.zeba.academy

šŸ“ŗ YouTube

https://www.youtube.com/@zeba.academy

šŸ“ø Instagram

https://www.instagram.com/zeba.academy/


If you found this package useful

⭐ Star the repository

šŸ‘ Like and share

šŸ› Report issues

šŸš€ Contribute improvements


Made with ā¤ļø by Zeba Academy