debounceWith<T> static method
dynamic Function(T)
debounceWith<T>(
- void func(
- T
- Duration delay = const Duration(milliseconds: 300),
Generic debounce function that passes value to callback
Example:
final debouncedSave = FSUtils.debounceWith<String>((value) => save(value));
textField.onChanged = debouncedSave;
Implementation
static Function(T) debounceWith<T>(
void Function(T) func, {
Duration delay = const Duration(milliseconds: 300),
}) {
Timer? timer;
return (T value) {
timer?.cancel();
timer = Timer(delay, () => func(value));
};
}