[英]How to filter data from backend using bloc future fetch stream?
我在团体上有这种方法
fetchProductAttribute(int _prodId) async {
List<ProductAttribute> productAttribute = await _repository.fetchProductAttribute(_prodId).catchError((err) => _fetcher.addError(err));
_fetcher.sink.add(productAttribute);
}
这将调用存储库,然后将rest api传递到后端。 现在我要过滤此数据。
我将对此进行修改,但无法正常工作...如何正确执行此操作?
fetchProductAttribute(int _prodId) async {
List<ProductAttribute> productAttribute = await _repository.fetchProductAttribute(_prodId).catchError((err) => _fetcher.addError(err));
for(var c in productAttribute){
if(c.variant==true){
_fetcher.sink.add(productAttribute);
}
}
}
所有数据仍在继续...我只希望在屏幕上显示变量true的数据。 这个怎么做?
我在这里和这里看到一篇有关如何通过使用StreamSubscription在Stream上进行过滤的文章,但这不是我想要的。 我想从REST的早期部分中过滤掉。
正如一条评论所述,在列表中使用where
运算符。
fetchProductAttribute(int _prodId) async {
List<ProductAttribute> productAttribute = await _repository.fetchProductAttribute(_prodId).catchError((err) => _fetcher.addError(err));
productAttribute = productAttribute.where((c) => c.variant == true).toList()
_fetcher.sink.add(productAttribute);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.