why to we need a service locator like get_it when we can use Singleton class in Flutter

59 views Asked by At

For creating API repository, DioClient, Database access class in flutter, we can use singleton pattern and create singleton classes. Then, what is the advantage of using service locators like get_it.

1

There are 1 answers

1
davidn On

True, we may not always need it. If you understand how get_it works, you can do some of the simplest things yourself. But it has proven useful because it further provides functionalities that a simple singleton alone may not suffice.

As much as I would love to explain, someone else has taken out time to do this, here is a link

https://medium.com/flutter-community/how-the-getit-service-locator-package-works-in-dart-fc16a2998c07

Hope it is helpful