android - Flutter - 如何根据List中的ID统计数据
问题描述
我有List<Comment>
所有食物。
[
{
comment_id: '...'
food_id: '...'
comment: '...'
},
{
comment_id: '...'
food_id: '...'
comment: '...'
},
....
]
我想知道如何计算基于food_id
Flutter 的评论数?任何答案都非常有帮助。
解决方案
您可以使用where(...)
过滤列表并.length
获取结果长度。
var comments = <Comment>[...];
var count = comments.where((c) => c.product_id == someProductId).toList().length;
推荐阅读
- reactjs - 我无法在我的反应索引 html 文件中引用背景图像
- python - 如何纠正写得不好的电子邮件?
- android - 是否有适用于 android 的 HttpClient 在连接失败时不重试?
- .htaccess - 将整个子文件夹重定向到新域
- dart - SafeArea 小部件中不安全区域的颤动背景。
- android - 如何毫无例外地添加'Admod's广告?
- html - ngif 比较两个数组
- c# - 面板的内容在给定时间内不会在视觉上更新,但之后会完全清除
- javascript - 负轴值使图表出现故障
- azure-devops - VSTS 构建:未找到 .NETFramework v4.6 程序集