From 77023ad1186ebae00f145a5d6eaf3ed279236c42 Mon Sep 17 00:00:00 2001 From: 98spag Date: Tue, 30 May 2023 17:15:35 +0200 Subject: [PATCH] feat: format helper --- lib/android/components/card_component.dart | 11 ----------- lib/android/config/format_helper.dart | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/android/components/card_component.dart b/lib/android/components/card_component.dart index 9665103..d5405b2 100644 --- a/lib/android/components/card_component.dart +++ b/lib/android/components/card_component.dart @@ -92,17 +92,6 @@ class _CardComponentState extends State { return calories.round(); } - 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; - } @override Widget build(BuildContext context) { return Card( diff --git a/lib/android/config/format_helper.dart b/lib/android/config/format_helper.dart index 76297ee..098156b 100644 --- a/lib/android/config/format_helper.dart +++ b/lib/android/config/format_helper.dart @@ -1,5 +1,20 @@ +import '../models/food.dart'; + 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; } + + +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; +} \ No newline at end of file