'The argument type 'RxString' can't be assigned to the parameter type 'String'

I try to use the GetX framework in flutter for my project. but it shows the Error regarding RxString. whenever I try to use the Obx method to call the controller object inside a text widget or a other String parameter widget it shows the error

The argument type 'RxString' can't be assigned to the parameter type 'String'

this is my controller class

var qrValue = "waiting".obs;

socket.on('event', (data) 
{
    var qr = data['final'];
    qrValue.value = qr;
    print(qrValue);
 }

this want to pass the data to generate the qrcode

Obx(() => QrImage(
data: _controller.qrValue,
version: QrVersions.auto,
size: 200.0,
 ),
 )),

when i pass the qrvalue to the argument it show the error

The argument type 'RxString' can't be assigned to the parameter type 'String'



Solution 1:[1]

You are passing directly the Rx to the data property of QrImage. You need to pass the value of the Rx:

data: _controller.qrValue.value,

Solution 2:[2]

If you don't want to append .value every time you access the controller's obs variable, consider setting a separate getter for the rx variable in the GetX Controller.

Add _ to the existing variable name, and let the getter replace the existing variable name.

//getXController

final _qrValue = "waiting".obs;
get qrValue => _qrValue.value; // use getter
//Widget 

Obx(() => QrImage(
  data: _controller.qrValue,
  version: QrVersions.auto,
  size: 200.0,
 ),
),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S. M. JAHANGIR
Solution 2 Jeremy Caney