flutter - 颤振力为列表中的所有对象设置属性值
问题描述
我有一个包含自定义对象的列表,并希望对其进行迭代并将值设置为 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;
在颤动中怎么可能?
解决方案
假设您要为 a 中的每个设置为,您isEnable
可以执行以下操作:false
Feature
List<Feature>
features.forEach((f) => f.isEnable = false);
或者
for (final f in features) {
f.isEnable = false;
}
推荐阅读
- ruby - 我无法在备用类的方法中调用属于某些类的方法
- f# - Process.start 用于启动浏览器,但现在已弃用
- angular - 订阅身份验证服务时,标头组件未更新
- javascript - 单击后如何从 DOM 中删除按钮元素?
- authentication - 在仅从其他应用程序接收数据的 Web API 中使用什么类型的身份验证
- xml - XSLT - 稍后在 XSLT 中使用标记属性
- c# - 用列表框中的项目填充对象属性?
- java - 使用 Java 中的 Scanner 类读取控制台中的字符输入
- c# - FromQuery 请求对象的 C# Swagger 注释
- odoo - Odoo - 查找和删除
标签