Getx: GetXController values not updating widgets when assigned a value

Created on 17 Mar 2021  路  5Comments  路  Source: jonataslaw/getx

class MyController extends GetxController {
  var test  = 0.obs;
}

in my class widget class, at first, I tried
myController.test++

and I could see updated value on
Obx(() => Text("The value is ${myController.test.value}"))

But when I assign a value using
myController.test = someIntegerValue

GetX doesn't update my Widget...

I want to use String values, and they don't seem to work either...

am I missing something?

Most helpful comment

class MyController extends GetxController {
  var test  = 0.obs;
}

in my class widget class, at first, I tried
myController.test++

and I could see updated value on
Obx(() => Text("The value is ${myController.test.value}"))

But when I assign a value using
myController.test = someIntegerValue

GetX doesn't update my Widget...

I want to use String values, and they don't seem to work either...

am I missing something?

would be: myController.test.value = someIntegerValue ? Or am I wrong?
you missed the .value

Remember your variable need to be an Rx.

All 5 comments

Please, provide a reproduce code

class MyController extends GetxController {
  var test  = 0.obs;
}

in my class widget class, at first, I tried
myController.test++

and I could see updated value on
Obx(() => Text("The value is ${myController.test.value}"))

But when I assign a value using
myController.test = someIntegerValue

GetX doesn't update my Widget...

I want to use String values, and they don't seem to work either...

am I missing something?

would be: myController.test.value = someIntegerValue ? Or am I wrong?
you missed the .value

Remember your variable need to be an Rx.

@Katekko is right. New value needs to be assigned to .value, not to the variable itself.
I think the documentation needs to be updated to use final rather than var as that would help to catch those errors right away because it wouldn't allow reassigning the actual variable. I don't think there's any good reason to use var here.

Exactly same issue here https://github.com/jonataslaw/getx/issues/1191
Trying to reassign the variables rather than .value on it

class MyController extends GetxController {
  var test  = 0.obs;
}

in my class widget class, at first, I tried
myController.test++
and I could see updated value on
Obx(() => Text("The value is ${myController.test.value}"))
But when I assign a value using
myController.test = someIntegerValue
GetX doesn't update my Widget...
I want to use String values, and they don't seem to work either...
am I missing something?

would be: myController.test.value = someIntegerValue ? Or am I wrong?
you missed the .value

Remember you variable need to be an Rx.

OMG... how did I miss that, I'll never know.
Thanks man :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Grohden picture Grohden  路  3Comments

aztecrabbit picture aztecrabbit  路  3Comments

williamsilva-98 picture williamsilva-98  路  4Comments

omartinma picture omartinma  路  3Comments

NiranjanShah picture NiranjanShah  路  4Comments