2023-05-30 17:15:35 +02:00
|
|
|
import '../models/food.dart';
|
|
|
|
|
2023-05-30 17:12:42 +02:00
|
|
|
String getFoodListStringByFood(String foodName, int count, int calories){
|
|
|
|
int maxWidth = 35;
|
|
|
|
String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ... $count x $calories kcal" : "$foodName $count x $calories kcal";
|
|
|
|
return limitedText;
|
|
|
|
}
|
2023-05-30 17:15:35 +02:00
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
String getWeeklyRankingString(String foodName){
|
2023-06-16 11:44:42 +02:00
|
|
|
int maxWidth = 40;
|
|
|
|
String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ..." : foodName;
|
2023-05-30 22:09:16 +02:00
|
|
|
return limitedText;
|
|
|
|
}
|
2023-05-30 17:15:35 +02:00
|
|
|
|
2023-06-02 18:18:08 +02:00
|
|
|
String getToastFoodNameString(Food food){
|
|
|
|
int maxWidth = 25;
|
2023-06-16 11:44:42 +02:00
|
|
|
String limitedText = food.name.length > maxWidth ? "${food.name.substring(0, maxWidth - 3)} ..." : food.name;
|
2023-06-02 18:18:08 +02:00
|
|
|
return limitedText;
|
|
|
|
}
|
|
|
|
|
2023-05-30 17:15:35 +02:00
|
|
|
Map<String,List<int>> getMapOfDistinctElementsWithCounterAndCalories(List<Food> foods){
|
|
|
|
Map<String,List<int>> resultMap = <String,List<int>>{};
|
|
|
|
for(int i = 0; i < foods.length;i++){
|
|
|
|
if(!resultMap.keys.contains(foods[i].name)){
|
|
|
|
resultMap.putIfAbsent(foods[i].name, () => [1,foods[i].calories]);
|
|
|
|
}else{
|
|
|
|
resultMap[foods[i].name]![0] = resultMap[foods[i].name]![0] + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resultMap;
|
2023-05-30 22:09:16 +02:00
|
|
|
}
|
|
|
|
|
2023-06-02 20:02:32 +02:00
|
|
|
|
2023-05-30 22:09:16 +02:00
|
|
|
List<Food> getListOfDistinctElements(List<Food> foods){
|
|
|
|
List<Food> result = [];
|
|
|
|
for(int i = 0; i < foods.length;i++){
|
|
|
|
if(!result.any((element) => element.id == foods[i].id)){
|
|
|
|
result.add(foods[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2023-05-30 17:15:35 +02:00
|
|
|
}
|