How can i prevent the users to accidentally press twice on the button thus placing the same order twice, using debouncing with timer?
I actually tried using debouncing on the button but I couldn’t figure it out.
Can someone explain it to me how can I achieve this?
I made a Timer? _dobounce in my widget state,
I made a method
void _onButtonPressed() {
if(_debounce?.isActive ?? false) _debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 500),(){
});
}
I am sure this method is not how its supposed to be and I dont know how to use it.
2
Answers
You can make
Debouncer
class usingTimer
Declare it
and trigger it
You can create such a class for the debouncing mechanism using Dart’s Timer class,
To use, wrap you method by DeBouncer.run method