'using http package in flutter for networking APIs is a good practice OR its better to use Retrofit, chopper or dio?
Actually I want to know which package is more beneficial from the user perspective, if there are other advantage pls let know in the comments. THANK YOU
Solution 1:[1]
From the user's (consumer's) perspective, http
/dio
/etc doesn't matter at all.
From a developer's perspective (my experience), it has been easier to handle exceptions with the dio
package than using http
. I had a lot of frustration trying to catch HTTP Response 500 when I was using http
, and my app keeps on crashing even though my code had a try
/catch
. Trying to add timeouts in my http
code has been especially difficult. But with dio
, they have a built-in solution (connectTimeout
).
Also in general, writing networking code with dio
(I haven't tried Chopper
or Retrofit
) is faster and easier than writing code using http
.
Solution 2:[2]
http is pretty simple - good for building demo or small project.
Chopper supports convertor and interceptor which are mostly good enough in most case. Plus, it has chopper_generator for generating part file. which is helpful and time-saving.
Dio has much more functionality and better documentation. A powerful Http client for Dart, which supports Interceptors, Global configuration, FormData, Request Cancellation, File downloading, Timeout etc. Chinese dev community love using this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Martin |
Solution 2 |