Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter mobx计算值第一次未在UI上更新(观察),但在重新加载后_Flutter_Mobx - Fatal编程技术网

Flutter mobx计算值第一次未在UI上更新(观察),但在重新加载后

Flutter mobx计算值第一次未在UI上更新(观察),但在重新加载后,flutter,mobx,Flutter,Mobx,我正在使用MobX管理应用程序的全局状态。问题是我在我的UI上使用了一些计算值,但这些值没有在UI上更新,但当我在mobx模式中打印这些值时,这些计算值计算正确 这是我的模型 abstract class _User with Store { _User(this.name, this.subjects); @observable String name; @observable List<Spend> subjects; @computed int

我正在使用MobX管理应用程序的全局状态。问题是我在我的UI上使用了一些计算值,但这些值没有在UI上更新,但当我在mobx模式中打印这些值时,这些计算值计算正确

这是我的模型

abstract class _User with Store {
  _User(this.name, this.subjects);

  @observable
  String name;

  @observable
  List<Spend> subjects;

  @computed
  int get totalSubjects => this.subjects.length;

  @action
  void addSubject(String name) {
    subjects.add(Spend(name));
    print(totalSubjects);
    // If i print the value this gives me correct length of subjects array, But this not oberving on UI
  }
}
抽象类\u用户与存储{
_用户(this.name,this.subjects);
@可观察
字符串名;
@可观察
列出主题;
@计算
int get totalSubjects=>this.subjects.length;
@行动
void addSubject(字符串名称){
添加(花费(姓名));
印刷品(全部主题);
//如果我打印该值,这将为我提供正确的主题数组长度,但这不会影响UI
}
}
只有计算值未更新。但当我添加主题时,主题会正确反映


我使用的是
flatter\u mobx:^1.1.0+2
sdk:>=2.7.0添加、删除或任何类型的列表更新都不会被观察到,如果你想使用一个被观察到的列表,那么使用
observebleList