How to replace deprectaed notifyProperty?

喜欢而已 提交于 2019-12-06 07:59:32

The suggestion from the devs is to keep the oldValue around in a private variable for reference. As for the newValue you can actually just pass the getter and it will compute it with the new values.

You will be looking at a class similar to this:

class MyElement extends Observable {
  @observable var foo, bar;
  var _oldValue;
  @reflectable get xyz => foo + bar;

  MyElement() {
    // we use the xyz getter to compute its own new value
    // notifyPropertyChange returns the new value for convenience :)
    notifyXyz() { _oldValue = notifyPropertyChange(#xyz, _oldValue, xyz); }
    onPropertyChange(this, #foo, notifyXyz);
    onPropertyChange(this, #bar, notifyXyz);
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!