Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter queue API requests to execute later

I am implementing an app that I should handle offline mode. When I check the internet connection and it is not connected, I should add the API request to a queue to be executed when the internet connection is back again.

How can I do that?

I tried to add class names and the method names to the queue, but couldn't call the method from a class dynamically.

I am using Dio package to handle API requests.

like image 247
Amani Elsaed Avatar asked Jun 28 '26 16:06

Amani Elsaed


1 Answers

if you remove await from your requests you can save them as Future<dynamic> for Example

Future<dynamic> response = Dio().get("http://www.google.com");

now You can save it in List<Future<dynamic>> myList = List() and when you want to call it

await myList[0]

Or

myList[0].then()

like image 181
mohandesR Avatar answered Jun 30 '26 06:06

mohandesR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!