Open nedStarck opened 2 years ago
just create your Rx<Int>?
types id;
And use obj.update((val)=> val.id = 1);
SoObx(()=> Text(obj.id.value)
will be heard
But the entity depends on Rx which use in state management. Is that true?
Usually just Entity().obs does the trick. Any object change, like id = 1, should change the id value and you will only use this in your controller, it is not directly linked to the model. check your code, probably a basic logic error. I'll give you an example of something I use here.
I have a service AuthService with User().obs.
I use this observable object object to load my observable user.
final user = User().obs;
In my controller when I want to update this value I do:
onChangedPassword(v) => auth.user.update((val) => val!.password = v);
and work :)
Usually just Entity().obs does the trick. Any object change, like id = 1, should change the id value and you will only use this in your controller, it is not directly linked to the model. check your code, probably a basic logic error. I'll give you an example of something I use here.
I have a service AuthService with User().obs.
I use this observable object object to load my observable user.
final user = User().obs;
In my controller when I want to update this value I do:
onChangedPassword(v) => auth.user.update((val) => val!.password = v);
and work :)
This solved my problem Thanks
I have a similar problem using multiple fields from an Object. Obx Widgets are rebuilding even if I update just the name of the user, it will also rebuild the age widget
class User{ String name; int age; }
Inside the controller I got:
final user = User().obs;
updateUserName(name) => user.update((val) => val!.setName(name));
updateUserAge(age) => user.update((val) => val!.setAge(age));
And my Obx widgets are pretty simple and look like this:
Obx(() { print("name rebuild"); return Text('Name: ${controller.user.value.name}'); }),
Obx(() { print("age rebuild"); return Text('Age: ${controller.user.value.age}'); }),
I have not seen any examples on how to listen to just one field. Both widgets are being rebuild, any idea how can I listen to just one field? The user has a lot more fields
I have changed the fields inside User class to be RxString and RxInt and I am now using ObxValue(controller.user.value.name) instead of Obx().
Is this good practice?
Listen to a field of an abs object.
I want to listen to changes of a field from obs object, for example,
I declare my entity in getx controller as obs value;
Now I want to follow changes of
id
field byever()
worker orlisten
method. But I must declareid
field in my entity as an obs value as follow:The entity classes mustn't depend on state management.
Resolve this problem, pls. @jonataslaw