【问题标题】:flutter force set a property value to all objects from a list颤振力为列表中的所有对象设置属性值
【发布时间】:2020-05-20 20:38:27
【问题描述】:

我有一个包含自定义对象的列表,并希望对其进行迭代并将值设置为 true/false。

看到了setAll 方法,但我不会只更改列表中每个对象的属性。

我的对象看起来像:

class Feature {
  String id;
  String title;
  String subtitle;
  IconData leftIcon;
  IconData topRightIcon;
  IconData bottomRightIcon;
  bool isEnable;
  Feature({this.title, this.subtitle, this.leftIcon, this.topRightIcon, this.bottomRightIcon, this.isEnable,this.id});
}

所以想要迭代的对象是:List<Feature> features;

在颤振中怎么可能?

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    假设您想为 List<Feature> 中的每个 FeatureisEnable 设置为 false,您可以执行以下操作:

    features.forEach((f) => f.isEnable = false);
    

    for (final f in features) {
      f.isEnable = false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-29
      • 2018-10-19
      • 2019-09-05
      • 1970-01-01
      • 2018-12-02
      • 2021-06-12
      • 1970-01-01
      • 2019-09-14
      相关资源
      最近更新 更多