I am new to flutter I have project where I have used bloc for state management and Dio for http request.
I am showing a Snack bar on error from rest Api now I want to resend a previous request if user click on retry button, I have provided in Snack bar, how can I do that, I know that there is something like cancel Token in Dio, but I don't know how to use it and if it is possible to do so by using it.
so, basically you want to cancel previous request and if user taps again on retry button in snackbar, so send the same new one? I think this code snippet may be useful for you if I understood your issue right. So firts I created bloc, but it os minimal example and you need to adapt it for you task
I created get request for getting data from api first. Also I create separate _retry function for tapping on button and cancel request and after it cancelling, it will create the new token for the next request and get data from Api again. It is the minimal example and of cource it needs to be re-work for your issue. Also interceptors in dio is required for convenient eay of error catching, it seems to me it has nothing to do with cancel request. But I can be wrong. Also there is some UI for checking how it works: