flutter_debouncer 2.0.0 copy "flutter_debouncer: ^2.0.0" to clipboard
flutter_debouncer: ^2.0.0 copied to clipboard

A Flutter plugin for debouncing can be used to simplify the implementation of debouncing logic in Flutter applications, making it easier to handle user interactions effectively.

Flutter Debouncer #

A Flutter plugin for debouncing can be used to simplify the implementation of debouncing logic in Flutter applications. It provides a convenient way to handle debouncing scenarios for user interactions, such as button presses or text input changes, in order to enhance the user experience and avoid unintended actions or frequent updates.

Features #

✅   Debouncing
✅   Throttling

Demo #

Quick Start #

Step 1: Include the package to your project #

dependencies:  
 flutter_debouncer: <latest version>  

Run pub get and get packages.

Step 2: Add this package to your project #

import 'package:flutter_debouncer/flutter_debouncer.dart';  

Step 3: Initialize Service #

For Debouncer

final Debouncer _debouncer = Debouncer();  

For Throttler

final Throttle _throttler = Throttler();  

Example #

Debouncing #

void _handleTextFieldChange(String value) {
  const duration = Duration(milliseconds: 500);
  _debouncer.debounce(
    duration: duration,
    onDebounce: () {
      setState(() {
        debouncedText = value;
      });
    },
  );
}

Throttling #

void _handleTextFieldChange(String value) {
  const duration = Duration(milliseconds: 500);

  _throttler.throttle(
    duration: duration,
    onThrottle: () {
      setState(() {
        throttledCounter++;
      });
    },
  );
}

Use type parameter to pass BehaviorType to change the behavior of the debounce or throttle #

void _handleTextFieldChange(String value) {
  const duration = Duration(milliseconds: 500);
  /// - [BehaviorType.leadingEdge] : The callback function is executed immediately
  _debouncer.debounce(
    duration: duration,
    type: BehaviorType.leadingEdge,
    onDebounce: () {
      setState(() {
        debouncedText = value;
      });
    },
  );
}

Cancel Debouncer or Throttler #

///Debouncer Cancel
_debouncer.cancel();

///Throttler Cancel
_throttler.cancel();

Project Created & Maintained By #

Syaif Akmal #

  
  

License #

Code released under the GNU GENERAL PUBLIC LICENSE Version 3.

11
likes
150
points
5.7k
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for debouncing can be used to simplify the implementation of debouncing logic in Flutter applications, making it easier to handle user interactions effectively.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

flutter

More

Packages that depend on flutter_debouncer