From b201a6758b64e789402285239096625dc9dd2475 Mon Sep 17 00:00:00 2001 From: 98spag Date: Tue, 30 May 2023 17:28:16 +0200 Subject: [PATCH] feat: add ingredient progress bars to page --- .../line_circular_with_text_component.dart | 10 +++++----- .../statistics_today_component.dart | 8 +++++--- lib/android/config/statistics.dart | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/android/components/circular/line_circular_with_text_component.dart b/lib/android/components/circular/line_circular_with_text_component.dart index 127afd2..ab41c94 100644 --- a/lib/android/components/circular/line_circular_with_text_component.dart +++ b/lib/android/components/circular/line_circular_with_text_component.dart @@ -5,28 +5,28 @@ import 'package:percent_indicator/linear_percent_indicator.dart'; class LineCircularWiTextComponent extends StatelessWidget { final Color progressColor; - final double percent; - final int left; + final double value; final int total; final String textName; const LineCircularWiTextComponent( - this.progressColor, this.percent, this.left, this.total, this.textName, + this.progressColor, this.value, this.total, this.textName, {super.key}); @override Widget build(BuildContext context) { + double progress = double.parse((value/total).toStringAsFixed(1)); return Padding( padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - StaticsTextComponent(left.toString(), true), + StaticsTextComponent(double.parse(value.toString()).toStringAsFixed(2), true), const SizedBox(height: 4,), LinearPercentIndicator( padding: EdgeInsets.zero, lineHeight: 8.0, - percent: 0.9, + percent: progress, progressColor: progressColor, ), const SizedBox(height: 4,), diff --git a/lib/android/components/meal_page_text/statistics_today_component.dart b/lib/android/components/meal_page_text/statistics_today_component.dart index 76ece27..7d6e06f 100644 --- a/lib/android/components/meal_page_text/statistics_today_component.dart +++ b/lib/android/components/meal_page_text/statistics_today_component.dart @@ -13,6 +13,7 @@ class StatisticsPercentage extends StatelessWidget { @override Widget build(BuildContext context) { StatisticsService statisticsService = StatisticsService(); + List ingredients = statisticsService.getAllEatenIngredientsForTodayStatistics(); return Container( decoration: BoxDecoration(border: Border.all(width: 2.0, color: Colors.black)), @@ -35,12 +36,13 @@ class StatisticsPercentage extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + // TODO adjust total values (200) to user inputs LineCircularWiTextComponent( - Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"), + Colors.green.shade400, ingredients[0], 200, "Fat (g)"), LineCircularWiTextComponent( - Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"), + Colors.green.shade400, ingredients[1], 200, "Protein (g)"), LineCircularWiTextComponent( - Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"), + Colors.green.shade400, ingredients[2], 200, "Carbohydrate (g)"), ], ), ) diff --git a/lib/android/config/statistics.dart b/lib/android/config/statistics.dart index 70f9881..3bb8040 100644 --- a/lib/android/config/statistics.dart +++ b/lib/android/config/statistics.dart @@ -176,6 +176,21 @@ class StatisticsService { return sum as int; } + List getAllEatenIngredientsForTodayStatistics(){ + Box box = Hive.box(reducedStatisticsBoxName); + num fat = 0; + num protein = 0; + num carbs = 0; + for(int i = 0; i < box.keys.length;i++){ + for(Food food in box.get(box.keys.elementAt(i))){ + fat += food.fatg; + protein = food.proteing; + carbs = food.carbohydrateg; + } + } + return [fat as double,protein as double,carbs as double]; + } + num getAllCaloriesByBoxAndTimestamp(Box box,int timestamp){ Map> valueMap = castDynamicMap(box.get(timestamp)); num sum = 0; @@ -203,6 +218,8 @@ class StatisticsService { return sum; } + + showItems(){ print("Statistics.dart - showItems() - ITEMS"); //Hive.box(boxName).clear();