skip to Main Content

There is no heavy widget, that why I am facing this issue:

Code:

 Obx(()=>InkWell(
          onTap: (){
            controller.login();
          },
          child: Container(
            alignment: Alignment.center,
            height: 50,
            width: 150,
            color: Colors.greenAccent,
            child: Text('Login Here'),
          ),
        ),
     ),

I just want to call this function properly, instead it gives me error of improper use of GetX

2

Answers


  1. the Getx has Obx widget in order that it triggeres updates if that widget uses some observable Rx, if you didn’t use any of it then this error is thrown since it is a waste of resources.

    you will need either to start using an actual observable Rx<T> inside of it if you need it. otherwise if you don’t want to update that widget then you don’t need to wrap it with Obx.

    Login or Signup to reply.
  2.  Obx(()=>InkWell(
              onTap: (){
                controller.login();
              },
              child: Container(
                alignment: Alignment.center,
                height: 50,
                width: 150,
                // If you are using an Obx-wrapped widget, you need a variable created with <Rx> that affects the widget's state. You do not need to use the Obx widget for the controller value accessed within the functions.
                color: controller.someRxBoolValue ? Colors.red : Colors.greenAccent,
                child: Text('Login Here'),
              ),
            ),
         ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search