easy_debounce_throttle

Creator: coderz1093

Last updated:

0 purchases

easy_debounce_throttle Image
easy_debounce_throttle Images
Add to Cart

Description:

easy debounce throttle

Easy Debounce Throttle














An easy-to-use flutter package that provides debounce and throttle with Stream and WidgetBuilder.
Usage #
If you want to subscribe to debounce, throttle events with Stream, use EasyDebounce, EasyThrottle
you should call the close() method to avoid memory leak
EasyDebounce #
final EasyDebounce _easyDebounce = EasyDebounce(delay: const Duration(milliseconds: 1000));
final TextEditingController _textController = TextEditingController();

@override
void initState() {
super.initState();
_textController.addListener(() {
_easyDebounce.debounce(_textController.text);
});
_easyDebounce.listen((data) {
setState(() {
_debounceText = '$data';
});
});
}

@override
void dispose() {
_easyDebounce.close();
super.dispose();
}
copied to clipboard
EasyThrottle #
final EasyThrottle _easyThrottle = EasyThrottle(delay: const Duration(milliseconds: 1000));
final TextEditingController _textController = TextEditingController();

@override
void initState() {
super.initState();
_textController.addListener(() {
_easyThrottle.throttle(_textController.text);
});
_easyThrottle.listen((data) {
setState(() {
_throttleText = '$data';
});
});
}

@override
void dispose() {
_easyThrottle.close();
super.dispose();
}
copied to clipboard
If you want to receive debounce and throttle events from methods such as onPressed callbacks with WidgetBuilder, use EasyDebounceBuilder and EasyThrottleBuilder.
EasyDebounceBuilder and EasyThrottleBuilder internally disposes the stream, so there is no need to call the close() method.
EasyDebounceBuilder #
EasyDebounceBuilder(
delay: const Duration(milliseconds: 1000),
builder: (context, debounce) {
return TextButton(
onPressed: () => debounce(() => _increaseDebounceCount()),
// onPressed: () {
// debounce(() {
// _increaseDebounceCount();
// });
// },
child: Text(
'increase debounce count',
style: kNotoSansBold14.copyWith(color: Colors.white),
));
}),
copied to clipboard
EasyThrottleBuilder #
EasyThrottleBuilder(
delay: const Duration(milliseconds: 1000),
builder: (context, throttle) {
return TextButton(
onPressed: () => throttle(() => _increaseThrottleCount()),
// onPressed: () {
// throttle(() {
// _increaseThrottleCount();
// });
// },
child: Text(
'increase throttle count',
style: kNotoSansBold14.copyWith(color: Colors.white),
));
}),
copied to clipboard
Examples #
An example can be found in the example directory of this repository.
A list of detailed examples can be found in this Examples Repository



EasyDebounce
EasyThrottle












EasyDebounceBuilder
EasyThrottleBuilder









Installing #
1. Depend on it #
Add this to your package's pubspec.yaml file:
dependencies:
easy_debounce_throttle: ^1.0.0
copied to clipboard
or
$ flutter pub add easy_debounce_throttle
copied to clipboard
2. Install it #
You can install packages from the command line:
$ flutter pub get
copied to clipboard
3. Import it #
Now in your Dart code, you can use:
import 'package:easy_debounce_throttle/easy_debounce_throttle.dart';
copied to clipboard
License #
MIT License

Copyright (c) 2022 seosh817

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.