Debouncer class
A debouncer is a utility class that allows you to debounce a function call. It is useful to prevent a function from being called too frequently. For example, if you have a function that is called when the user types in a search box, you can use a debouncer to prevent the function from being called too frequently. This is useful to prevent the server from being overwhelmed by too many requests.
Example:
class SearchCubit extends Cubit<SearchState> {
SearchCubit() : super(const SearchState());
late final Debouncer _debouncer = Debouncer();
void debouncedSearch(String searchQuery) {
_debouncer.run(() => emit(state.copyWith(searchQuery: searchQuery.trim())));
}
@override
Future<void> close() {
_debouncer.dispose();
return super.close();
}
Constructors
Properties
Methods
-
dispose(
) → void - Disposes the debouncer.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
run(
VoidCallback action) → void - Runs the given action after the delay.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited