Search code examples
flutterflutter-getx

How using one element UI in multi getx controllers in flutter


I have a custom widget and this widget shared in multi pages but each page have it getx controller and. I need to put data inside the controllers come frome this widget How can i solve this problem in flutter

I expect use custom widget tget data from it like images for example And put this data inside controller But i have many controllers using this custom widget


Solution

  • You can create an instance of the control class and use it like the code below

    for example it's your base class which has image data :

    class A extends GetxController{
       File image = File('imagePath');
       File get getImage => image;
    }
    

    and now you would like to use it in side an other class which extends GetxController too use code blow

    class B extends GetxController{
    final myController = Get.put(A());
    myController.getImage();
    }
    

    This is an example of how to create instances of Getx classes