reset method
void
reset()
Resets the current timer and clears the callback.
This reset method cancels the execution of the current timer, if it was active, and releases the resources associated with the timer and callback. It is useful for preventing unwanted repeat calls when needed. cancel previous scheduled actions before scheduling new ones.
Usage example:
final _debounce = Debounce(delay: const Duration(milliseconds: 300));
void onTextChanged(String text) {
_debounce(() {
// ...
});
}
void reset() {
_debounce.reset();
}
Implementation
void reset() {
_timer?.cancel(); // Stop the timer if it is still running
_timer = null; // Delete the timer reference to free up memory
_callback = null; // Clearing the callback so that it does not hang in memory
_hasCalledLeading = false; // Resetting the leading flag
}