Home > database >  Create Getx controllers on demand with Bindings
Create Getx controllers on demand with Bindings

Time:10-28

I am looking forward to creating controller on demand with a different tag which binds with the Bindings defined. Is there any way to do this in Getx?

CodePudding user response:

try this if this one you looking

Am using routenamed and bind the binding from GetPage

e.g.

bindings

class BindingControllers with Bindings{

@override
void dependencies(){
  Get.lazyPut(()=> Controller1,fenix: true);
  Get.lazyPut(()=> Controller2,fenix: true);
  Get.lazyPut(()=> Controller3,fenix: true);
  }
}

Controller

class Controller1 extends GetxController{
  // as per origin using controller on the page
 // my case i use get find.
  final findController2 = Get.find<Controller2>();
  final findController3 = Get.find<Controller3>();
// so in this case you won't to put this on UI but on the controller
// on the ui side you can call this controller.findController1 and other controller you did bind.
}

GetPage

final list = <GetPage>[
   
    GetPage(
       name: "/dashboard",
       binding: BindingControllers(),
       page:()=> const DashBoard()
     ),

];

CodePudding user response:

I was able to figure out the answer it can be done using bindingBuilder which will create controller with bindings in runtime

The Documentation can be found here https://chornthorn.github.io/getx-docs/dependency-management/binding/#bindingsbuilder

  • Related