Bindings

Learn about bindings, the classes where we initialize dependencies and bind them to the routes.

What are bindings?

Bindings are classes where we declare and initialize all our dependencies and bind them to the routes. This unique feature lets us separate dependency initialization from the presentation layer (widgets), making the code more organized.

Creating a bindings class

The class we create should implement the Bindings class and override its dependencies method. Inside the method, we can initialize all our dependencies using any dependency injection method, such as Get.put, Get.lazyPut, or Get.putAsync.

Let’s see what the class looks like:

Press + to interact
class HomeBinding implements Bindings {
@override
void dependencies() {
// This is where we initialize all our dependencies.
Get.put<Controller1>(Controller1());
Get.put<Controller2>(Controller2());
}
}

The bindings class is ready. We can now bind this class to a route.

Binding the dependencies to a route

We bind dependencies to a route using GetX route management. We’ll talk about route ...