zeba_academy_debouncer 1.0.0
zeba_academy_debouncer: ^1.0.0 copied to clipboard
A lightweight Flutter package for debounce, throttle, timer execution, search optimization and cancelable callbacks.
zeba_academy_debouncer #
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 #
š» Coding Platform #
šŗ 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