Is it ok to use both GetX and Get_it at the same time?

714

It is possible to just use GetX and still be able to access dependencies form outside the widget tree.

///Inject
Get.put(CartService());
///Retrieve
CartService cartService = Get.find();

GetX has a built in service locator just as Get_it works. Although they don't share the same features the one you are looking for GetX does the trick.

You could use both, but if GetX already has this functionality built in and it works correctly I don't see why you would need to access get _it.(Maybe to use injectable?)

Share:
714
Shaw
Author by

Shaw

Updated on December 31, 2022

Comments

  • Shaw
    Shaw over 1 year

    I want to use GetX in my flutter project for state management. I don't know how I can achieve dependency injection with GetX though. Is it ok to use Get_it along with GetX in the same project? I feel like doing so makes the code cluttered. Or should I create a binding class with GetX and use it as initialBinding to achieve dependency injection?

    I want to be able to inject dependencies into non-view classes. What is the best practice for this?

    Using GetX + Get_it or is it possible with GetX alone?

    Thanks

  • Shaw
    Shaw over 2 years
    Thanks a lot. I just couldn't find any information on how to manage all the project's dependencies in one centralized location using GetX as it is done with Get_it package. So I think I should just create a separate class for dependencies and write all DI code in there.
  • rsobies
    rsobies almost 2 years
    thanks. exactly I need to use injectable to inject different implementation of some services depending test or dev environment. I dont think I could achieve it with getX?
  • croxx5f
    croxx5f almost 2 years
    No @rsobies, the code-gen and environment based dependencies are just AFAIK in the injectable package (which uses get_it under the hood). Either one you choose, injectable or getx, be consistent in your code and stick to one solution.