Skip to content

Using Same Object Multiple Times (To Use Multiple APIs using Get It & Dio Package) #250

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

Closed
milan-7span opened this issue Feb 1, 2022 · 2 comments

Comments

@milan-7span
Copy link

milan-7span commented Feb 1, 2022

I am using Get It for State management for my Flutter App

I want to use multiple APIs with Dio Package.

What i have done:
I have added two Dio Clients for two different APIs
I have add these two lines for registering Dio Clients in Get It.

// First API (Dio Client)
_getIt.registerSingleton(DioClient().getDio());

// Second API (Dio Client)
_getIt.registerSingleton(DioAnotherClient().getDio());

I am Facing this error after doing this:
E/flutter (13845): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument(s): Object/factory with type Dio is already registered inside GetIt.

I am seeking a solution to Use Multiple APIs using GetIt & Dio Package.

Can anyone provide a solution to this issue?

@escamoteur
Copy link
Collaborator

Hi,
it's actually very easy to fix for that case you have to provide different instanceNames when registerinf and use that too when you access the instances

@milan-7span
Copy link
Author

Hi, it's actually very easy to fix for that case you have to provide different instanceNames when registerinf and use that too when you access the instances

Okay, Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants