Back to results for “State Management”
Flutter › State Management with GetX

How does GetX's own simple built in dependency injection system, using Get.put and Get.find, let you properly register and later retrieve a shared controller instance from anywhere throughout your entire app?

Intermediate

Answer

Get.put registers a genuinely new controller instance within GetX's own internal dependency container, making that particular instance available for retrieval from essentially anywhere else throughout your entire app, and Get.find then properly retrieves that exact same already registered instance whenever it is genuinely actually needed elsewhere, providing a genuinely simple, considerably lightweight alternative to a genuinely more formal, separate dedicated dependency injection package such as GetIt, all conveniently bundled together within that exact same unified GetX package itself.
Get.put(CounterController());

// Elsewhere in the app
final controller = Get.find<CounterController>();
Real-world example A settings screen retrieves an already registered shared UserController instance using Get.find, accessing that exact same shared user data without needing to manually pass that particular controller down through several genuinely separate intermediate widget constructors.

Common follow-ups: What genuinely happens if you call Get.find for a controller that was never actually genuinely registered with Get.put in the first place?;What is the specific practical difference between Get.put and the considerably more genuinely lazy Get.lazyPut?