debounce static method
Debounce function for limiting frequent function calls
Delays function execution until after wait time has elapsed since last call. Useful for search inputs, resize events, etc.
Example:
final debouncedSearch = FSUtils.debounce(() => performSearch());
searchController.addListener(debouncedSearch);
Implementation
static VoidCallback debounce(
VoidCallback func, {
Duration delay = const Duration(milliseconds: 300),
}) {
Timer? timer;
return () {
timer?.cancel();
timer = Timer(delay, func);
};
}