Closed TheHypnoo closed 2 years ago
I think this is not in the scope of the package; for this use case, you should implement debouncing in the function/event that fires the Flushbar
.
I think this is not in the scope of the package; for this use case, you should implement debouncing in the function/event that fires the
Flushbar
.
@TheHypnoo Here is an example of a simple Debouncer
utility class I always use.
import 'dart:async';
typedef VoidCallback = void Function();
void main() {
final debouncer = Debouncer(delay:const Duration(milliseconds:300));
for (int i = 0; i < 5; i++) {
debouncer.run(()=>print(i)); // Will print only the last value of i -> 4.
}
}
class Debouncer{
Debouncer({required this.delay});
final Duration delay;
Timer? timer;
/// Runs the function [action]. If this method is called multiple times in less
/// than [delay], only the last call will be executed.
void run(VoidCallback action){
if(timer != null && timer!.isActive){
timer!.cancel();
}
timer = Timer(delay, action);
}
void dispose(){
timer?.cancel();
}
}
Hi, I have a doubt. In this case, pressing a button shows a Flushbar, but if you press it several times or something like that, it shows more times, what would be the way to not show it?