Getx: Workers doesn't listen to changes in Classes

Created on 3 Mar 2021  路  1Comment  路  Source: jonataslaw/getx

Hi,

Could you consider make the workers listen also to changes in attributes of custom objects?
It works so good with strings, double, etc. But when the observable is a custom object, it doesn't work.

Works: =========================

class HomeController extends GetxController {
final acuCtrl = .0.obs;
@override
void onInit() {
debounce(
acuCtrl,
(_) => print("debouce$_"), time: Duration(seconds: 1));
super.onInit();
}
}

: =========================
Doesn't work (// Doesn't trigger when simulaDados.value.attribute1 or simulaDados.value.attribute2 changes...)

class HomeController extends GetxController {
Rx simulaDados = SimulaModel().obs;@override
void onInit() {
debounce(
simulaDados,
(_) => print("debouce$_"), time: Duration(seconds: 1));
super.onInit();
}
}


Oi Jonatas, tem como fazer os workers ouvirem tamb茅m mudan莽as de atributos de minha classe? 脡 que no meu projeto n茫o tem muita vari谩vel "solta" no controller, a maioria fica em objetos.

(PS.:Parab茅ns, Jonatas, o GetX mudou meu astral para lidar com Flutter!)

Most helpful comment

I'm sure it works well .

class TestController extends GetxController{
  var count = 0.obs;

  final user = User().obs;

  //the first way to update user
  changeUserOne(){
    user.update((val) {
      val.name = 'John';
      val.age = 18;
    });
  }

  //the second way to update user
  changeUserTwo(){
    user(User(name: "Tick",age: 35));
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    debounce(
        user,
        (value){
          print("debounce finish : ${value.name} || ${value.age}");
        },
        time: Duration(seconds: 1)
    );
  }
}

// model
class User{
  User({this.name = "",this.age = 0});
  String name;
  int age;
}

>All comments

I'm sure it works well .

class TestController extends GetxController{
  var count = 0.obs;

  final user = User().obs;

  //the first way to update user
  changeUserOne(){
    user.update((val) {
      val.name = 'John';
      val.age = 18;
    });
  }

  //the second way to update user
  changeUserTwo(){
    user(User(name: "Tick",age: 35));
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    debounce(
        user,
        (value){
          print("debounce finish : ${value.name} || ${value.age}");
        },
        time: Duration(seconds: 1)
    );
  }
}

// model
class User{
  User({this.name = "",this.age = 0});
  String name;
  int age;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NO-ob picture NO-ob  路  4Comments

williamsilva-98 picture williamsilva-98  路  4Comments

definev picture definev  路  3Comments

rupamking1 picture rupamking1  路  3Comments

manojeeva picture manojeeva  路  3Comments