feat: format helper

feature/chart-progress-page
98spag 2023-05-30 17:15:35 +02:00
parent 0fd7def1e4
commit 77023ad118
2 changed files with 15 additions and 11 deletions

View File

@ -92,17 +92,6 @@ class _CardComponentState extends State<CardComponent> {
return calories.round(); return calories.round();
} }
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;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Card( return Card(

View File

@ -1,5 +1,20 @@
import '../models/food.dart';
String getFoodListStringByFood(String foodName, int count, int calories){ String getFoodListStringByFood(String foodName, int count, int calories){
int maxWidth = 35; int maxWidth = 35;
String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ... $count x $calories kcal" : "$foodName $count x $calories kcal"; String limitedText = foodName.length > maxWidth ? "${foodName.substring(0, maxWidth - 3)} ... $count x $calories kcal" : "$foodName $count x $calories kcal";
return limitedText; return limitedText;
} }
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;
}