The Obx Widget

Learn to handle state changes from multiple controllers using Obx.

Overview

Obx is an extremely simple widget with a single purpose—to listen to changes in the controller. We don’t need to provide the controller type or initialize the controller. It even has the ability to listen to multiple controllers from a single widget.

However, this simplicity comes at a price. We cannot initialize or attach controllers to Obx. It does not provide any life cycle controls and is not responsible for disposing of the controllers.

Initializing controller

So, how do we initialize the controllers? By using dependency injection! We can use any of the dependency injection techniques provided by GetX to use controllers with Obx, be it bindings, Get.put, Get.lazyPut, or Get.create. Let’s use Get.put in this lesson.

Here’s how we do it:

Get hands-on with 1400+ tech skills courses.