skip to Main Content

I am using only Text widget inside an Obx widget but I’m getting this issue

[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.

please solve this error.

2

Answers


  1. This error is thrown when you use an Obx widget without using really any Rx<T> variables inside of it, so the library notifies you that there is no point wrapping some widget that will not update based on some Rx<T> with the Obx.

    Example of what causes this:

    Controller:

    class ControllerExample extends GetxController {
     Rx<String> exampleText = "example".obs;
    }
    

    View:

    // Right
    Obx(() => Text(Get.find<ControllerExample>().exampleText.value)), // Text widget takes an Rx<T> variable as value, so it will work fine
    
    // Wrong
    Obx(() => Text("anotherExample")), // this is just showing a Text widget which do not have any relation to an Rx<T> so it will throw the error you're facing
    
    Login or Signup to reply.
  2. using Obx(()=>) without the Observable variable in view will throw this error.

    you have to use observable variables like i.e.

    RxString a = "".obs;
    RxInt b = 0.obs;
    RxBool c = false.obs;
    

    you have to use .value when accessing value in the view.

    Obx(
      () => Text(controller.a.value),
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search