update controller is not working in getx state management

25 views Asked by At

in my app i have this icon

enter image description here

when user taped on it the Coordinates address will changes to human readable address and hiding the eye icon I am using getx to update the state in this code icon is hiding but address text is not changing here is the code:


if (!ctl.isAddressAvailable) // here checking to show the icon
  InkWell(
    child: Icon(
      Icons.remove_red_eye,
      color: Colors.white,
    ),
    onTap: () async {
      String _returnedAddress =
          await Traccar.getAddressByCoorinate(
              ctl.deviceLatLang.latitude.toString(),
              ctl.deviceLatLang.longitude.toString());
      latlang.value = _returnedAddress; // i am updating the address text
      print(latlang);
      if (_returnedAddress.isNotEmpty) {
        ctl.isAddressAvailable = true; // here hiding the icons
      }
      ctl.update(); // here updating state
    },
  ),

the problem is with

ctl.update();

when I comment it the address change as well but the icon is not hiding also I putted the ctl.update(): to a delay function at first address change to hymen readable address and icon is steel appears cuse the state not updated yet, after 3 seconds `state update calling and the the address changes to coordinates address and icon is hiding.
please lemme know what to do?

1

There are 1 answers

0
Aesha On

I have gone through you code.

As per your code provide you have not used RxBool variable for this instead you only use bool isAddressAvailable Please try to implement this

RxBool isAddressAvailable = false.obs;

if (!ctl.isAddressAvailable.value) InkWell( child: Icon( Icons.remove_red_eye, color: Colors.white, ), onTap: () async { String _returnedAddress = await Traccar.getAddressByCoorinate( ctl.deviceLatLang.latitude.toString(), ctl.deviceLatLang.longitude.toString()); latlang.value = _returnedAddress; // i am updating the address text print(latlang); if (_returnedAddress.isNotEmpty) { ctl.isAddressAvailable.value = true; // here hiding the icons } ctl.update(); // here updating state }, ),

And wrap this whole widget with Obx