作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有两个名为 list1 和 list2 的列表。
list1 用于显示使用 ListView.builder 的学生列表
ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
return Text(list1[index]);
}
)
list1 包含所有学生的名字
现在 list2 只包含少数学生的姓名。如果 list2 中存在学生姓名,我需要更改学生姓名的颜色。如何将 list2 的每一项与 ListView.builder
list2 与 list1 不同。 list2 只包含几个学生的名字。
最佳答案
如何执行此操作的示例:
ListView.builder(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
var color;
if (list2.contains(list1[index])) {
//The name is present in list2
color = Colors.green;
} else {
//The name is not present in list2
color = Colors.black;
}
return Text(
list1[index],
style: TextStyle(
color: color,
),
);
}
)
您可以在 if/else 语句中执行更多操作来自定义您的小部件。
关于flutter - 如何将 List 的每一项与 ListView 构建器的每一项进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57188272/
我是一名优秀的程序员,十分优秀!