-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Should Dio object created as singleton #613
Comments
I'm just taking a look at this plugin, so I didn't read the documentation, but in Flutter you can instantiate anything using factory. An example: class CustomDio { factory CustomDio() { Even using http and thinking of using Dio for the first time today, to my knowledge you should close the http connection when no more requests are made, or when a downtime limit is reached. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
Any news if is correct to create a singleton? |
@Allan-Nava Yes, it is correct in my opinion. Already used singleton for my production apps and it's working fine. |
can you share your code to create dio with singleton partten? |
you can just create is using get_it dependency injection package and use it in every file.. i am doing the same here's the code: getIt.I |
I have created this dio service please check here. https://gist.github.com/naumanahmed19/9b5a42bb0eeeb7d0f6a76ac023a20eae |
Since I did not find an answer to this question in the documentation, I must ask here :)
Question:
I am creating class/service that will handle http requests, I will use Dio library, but I have a concern regarding the performance, do I need to declare dio object as static instance in order to save some resources? Is It necessary?
For example:
static const Dio http = Dio();
And do I have to call close() method every time I finished with http request?
Please advice.
Thanks,
Lazar
The text was updated successfully, but these errors were encountered: