Home > Net >  how can i render a widget according to condition getx?
how can i render a widget according to condition getx?

Time:01-05

I can not rendering a widget according to a condition using GetX?

the error i get is :

[Get] the improper use of a GetX has been detected. You should only use GetX or Obx for the specific widget that will be updated. If you are seeing this error, you probably did not insert any observable variables into GetX/Obx or insert them outside the scope that GetX considers suitable for an update (example: GetX => HeavyWidget => variableObservable). If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.

the code is:

 GetX<ImageController>(builder: (co){
                      if(co.photo== null){
                        return  const Center(child: Text("pick img"));
                      }else{
                        return Text("${co.photo}");
                      }
                    }),

CodePudding user response:

You can simply use Obx instead of GetX, it's easier and uses less code. also. when you are using GetX or Obx, you need to use ann observable variable inside it. it means your photo should have .obs at the end of it when defining. like the code bellow:

class Controller extends GetxController{
  var count = 0.obs;
  increment() => count  ;
}

Obx(() => Text("Clicks: ${c.count}"))

it will work, because inside Obx or Getx there is a obs variable.

CodePudding user response:

This error is showing because ImageController was not provided. try.

GetBuilder<ImageController>(init:ImageController(),builder:(co){
                  if(co.photo== null){
                    return  const Center(child: Text("pick img"));
                       }else{
                    return Text("${co.photo}");
                  }
                })
  •  Tags:  
  • Related