Reputation: 19434
Effective Dart warns about avoiding forEach. Use build in for-in instead.
Is there any better way? I want to wait
and return
.
List<PromotionModel> allPromotion = //add data from api;
Future<List<PromotionModel>> filterPromotion() async {
List<PromotionModel> temp = [];
if(!check){
return allPromotion;
}else{
await Future.forEach(allPromotion, (v) async {
if(v.vendoruid == uid){
temp.add(v);
}
});
return temp;
}
}
Upvotes: 0
Views: 172
Reputation: 6161
Assuming that allPromotion
is of Future<List>
type, just await
the future and loop through the provided list like so:
final list = await allPromotion;
for (var v in list) {
if (v.vendoruid == uid) {
temp.add(v);
}
}
return temp;
Upvotes: 1