Home > Software engineering >  Is it possible to create a separate Getx Controller for a reusable widget?
Is it possible to create a separate Getx Controller for a reusable widget?

Time:07-22

Is it possible to use getx controller to manage state for reusable widget type? I want to create a small widget such as an elegant number button widget for the shopping cart section with each widget having a separate controller that does not share data with each other. Is it possible to do so and should it be done? Please advise me. Sorry for my bad English

CodePudding user response:

Yes, it looks like Magic, Get will find your controller, and will deliver it to you. You can have 1 million controllers instantiated, Get will always give you the right controller.

Controller controller = Get.find();

CodePudding user response:

No you cannot. It is always recommended to keep the the reusable widget a stateless widget that takes data to show in widget view. Then on top of that reusable widget you can wrap with GetBuilder and give its own controller that can have its own data separate.

  • Related