import 'package:flutter/cupertino.dart'; import '../models/food.dart'; String getFoodListStringByFood(String foodName, int count, int calories, BuildContext? context){ int maxWidth = 35; if(context != null){ maxWidth = isScreenWidthAbove1000(context) ? 100 : 35; } String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ... $count x $calories kcal" : "$foodName $count x $calories kcal"; return limitedText; } bool isScreenWidthAbove1000(BuildContext context) { double screenWidth = MediaQuery.of(context).size.width; return screenWidth > 400; } String getWeeklyRankingString(String foodName,BuildContext? context){ int maxWidth = 40; if(context != null){ maxWidth = isScreenWidthAbove1000(context) ? 100 : 40; } String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ..." : foodName; return limitedText; } String getToastFoodNameString(Food food,BuildContext? context){ int maxWidth = 25; if(context != null){ maxWidth = isScreenWidthAbove1000(context) ? 100 : 25; } String limitedText = food.name.length > maxWidth ? "${food.name.substring(0, maxWidth - 3)} ..." : food.name; return limitedText; } Map> getMapOfDistinctElementsWithCounterAndCalories(List foods){ Map> resultMap = >{}; 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; } List getListOfDistinctElements(List foods){ List result = []; for(int i = 0; i < foods.length;i++){ if(!result.any((element) => element.id == foods[i].id)){ result.add(foods[i]); } } return result; }