You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a city navigation app, to search for interesting places. I have categories (parks, cinemas, nightclubs, etc.) and a search textfield.
I enter the text and do a debounced search with reaction:
But what if I started typing and decided to change the category, and rapidly tapped to the another category chip?
In this case, I changed the category, but a search for previous category still has been executed.
I need a way to interrupt debounce.
Consider providing some API like
reactionDisposer.cancelScheduledReaction();
The text was updated successfully, but these errors were encountered:
@subzero911
I think _searchPlaces should handle that.
method 1. Shows only the results of the last request
DateTime _lastSearchTime;
Future<void> _searchPlaces() async {
final searchTime =DateTIme.now();
_lastSearchTime = searchTime;
final result =awaitnetworkCall();
if ( _lastSearchTime <= searchTime) {
// show result
}
};
method 2. cancel previous request
// use dio.CancelToken? _token;
Future<void> _searchPlaces() {
// Cancel if there is a previous request
_token?.cancel('cancel');
_token =CancelToken();
dio.get(url, cancelToken: token)
.catchError((DioError err){
if (CancelToken.isCancel(err)) {
print('Request canceled! '+ err.message)
}else{
// handle error.
}
});
};
I have a city navigation app, to search for interesting places. I have categories (parks, cinemas, nightclubs, etc.) and a search textfield.
I enter the text and do a debounced search with reaction:
But what if I started typing and decided to change the category, and rapidly tapped to the another category chip?
In this case, I changed the category, but a search for previous category still has been executed.
I need a way to interrupt debounce.
Consider providing some API like
reactionDisposer.cancelScheduledReaction();
The text was updated successfully, but these errors were encountered: