GetIt – no BuildContext required
GetIt is an approach that uses the setState
functionality to update the UI and leverages the power of dependency injection to give access to model classes to the whole application. It also doesn't require BuildContext
to update and manage any states anywhere inside your application.
Note
If you want to learn more about dependency injection in general, please visit the wiki page (https://en.wikipedia.org/wiki/Dependency_injection).
Let's see how our counter example is built using GetIt.
Adding a GetIt dependency in a sample application
Create a new application using any name you want, just like we did in the previous chapters:
flutter create any_name_you_wish
You will get the same counter example application with the default setState
management technique implemented to update the counter value.
Let's see how to embed GetIt into your application code:
- Open up a browser and go to https://pub.dev/. ...