From f25de45f7c1a0ed47d3c2451bd5fabb923b29671 Mon Sep 17 00:00:00 2001 From: 98spag Date: Thu, 1 Jun 2023 12:14:23 +0200 Subject: [PATCH] feat: adjustments --- .dart_tool/package_config.json | 2 +- .env | 9 +- .flutter-plugins-dependencies | 2 +- .../components/MealPageFoodComponent.dart | 3 +- .../components/card/card_component.dart | 11 +- .../components/food_list_component.dart | 3 +- .../components/founded_search_component.dart | 11 +- .../meal_page_text/days_component.dart | 7 +- lib/android/config/setup_todaybox_config.dart | 2 +- lib/android/config/statistics.dart | 194 ++++++++++++++++-- .../pages/nav_pages/progress_page.dart | 110 ++-------- lib/android/pages/nav_pages/today_page.dart | 3 +- lib/main.dart | 11 +- 13 files changed, 230 insertions(+), 138 deletions(-) diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index c5ce656..6195997 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -584,7 +584,7 @@ "languageVersion": "2.19" } ], - "generated": "2023-05-30T14:26:53.205127Z", + "generated": "2023-06-01T10:00:31.814419Z", "generator": "pub", "generatorVersion": "3.0.2" } diff --git a/.env b/.env index 8cb26a6..f9175c3 100644 --- a/.env +++ b/.env @@ -4,10 +4,15 @@ SECOND_NAME_FIELD=SECOND_NAME WEIGHT_FIELD=WEIGHT HEIGHT_FIELD=HEIGHT CALORIES_FIELD=CALORIES -TODAY_BOX=TODAY + DATE_FIELD=DATE # datum BREAKFAST_FIELD=FRÜHSTÜCK # frühstück LUNCH_FIELD=MITTAGESSEN # mittagessen DINNER_FIELD=ABENDESSEN # abendessen YESTERDAY_AND_BEFORE=YESTERDAY # gestern und alles was davor war -TOMORROW_AND_AFTER=TOMORROW # morgen und alles was kommen wird \ No newline at end of file +TOMORROW_AND_AFTER=TOMORROW # morgen und alles was kommen wird + +MEALPLAN_BOX=MEALPLAN +STATISTICS_TODAY_BOX=STATISTICS_TODAY +STATISTICS_PROGRESS_BOX=STATISTICS_PROGRESS +STATISTICS_MAIN_BOX=STATISTICS_MAIN \ No newline at end of file diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index e6a219b..b3939d2 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-05-30 20:39:45.634550","version":"3.10.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\FUCHSLAU\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.6\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2023-06-01 12:00:31.954526","version":"3.10.2"} \ No newline at end of file diff --git a/lib/android/components/MealPageFoodComponent.dart b/lib/android/components/MealPageFoodComponent.dart index 50e2a09..c62a067 100644 --- a/lib/android/components/MealPageFoodComponent.dart +++ b/lib/android/components/MealPageFoodComponent.dart @@ -1,4 +1,5 @@ import 'package:ernaehrung/android/components/food_list_component.dart'; +import 'package:ernaehrung/android/config/statistics.dart'; import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; import 'meal_page_text/title_component.dart'; @@ -19,7 +20,7 @@ class MealPageStatisticsFoodComponent extends StatelessWidget { height: 24, ), const TitleComponent("Nahrung"), - FoodComponent(box: Hive.box('STATISTICS_REDUCED'),) + FoodComponent(box: Hive.box(StatisticsService.instance.todayStatisticsBoxName),) ], ), ); diff --git a/lib/android/components/card/card_component.dart b/lib/android/components/card/card_component.dart index 56d6e1b..92cd565 100644 --- a/lib/android/components/card/card_component.dart +++ b/lib/android/components/card/card_component.dart @@ -1,9 +1,8 @@ import 'package:basic_utils/basic_utils.dart'; import 'package:ernaehrung/android/components/card/card_data_food_component.dart'; import 'package:ernaehrung/android/components/card/card_title_component.dart'; +import 'package:ernaehrung/android/config/cast_helper.dart'; import 'package:flutter/material.dart'; - -import '../../models/food.dart'; import '../../pages/nav_pages/search_food.dart'; class CardComponent extends StatelessWidget { @@ -12,14 +11,6 @@ class CardComponent extends StatelessWidget { const CardComponent(this.title, this.foods, {super.key}); - List castDynamicToListFood(List dynamicList) { - List foodList = []; - for (Food element in dynamicList) { - foodList.add(element); - } - return foodList; - } - Route createRoute(String cardName) { return PageRouteBuilder( pageBuilder: (context, animation, secondaryAnimation) => diff --git a/lib/android/components/food_list_component.dart b/lib/android/components/food_list_component.dart index 81075c7..b05b1d1 100644 --- a/lib/android/components/food_list_component.dart +++ b/lib/android/components/food_list_component.dart @@ -1,4 +1,5 @@ import 'package:ernaehrung/android/config/cast_helper.dart'; +import 'package:ernaehrung/android/config/statistics.dart'; import 'package:flutter/cupertino.dart'; import 'package:hive_flutter/adapters.dart'; import 'card_component.dart'; @@ -24,7 +25,7 @@ class FoodComponent extends StatelessWidget { return CardComponent( eatingMealName: box.keyAt(i).toString(), selectedMeal: castDynamicToListFood(box.getAt(i)), - addButtonVisible: box.name != 'statistics_reduced', + addButtonVisible: box.name != StatisticsService.instance.todayStatisticsBoxName.toLowerCase(), ); } }); diff --git a/lib/android/components/founded_search_component.dart b/lib/android/components/founded_search_component.dart index 889d645..2d55583 100644 --- a/lib/android/components/founded_search_component.dart +++ b/lib/android/components/founded_search_component.dart @@ -16,15 +16,14 @@ class SearchedFoodComponent extends StatefulWidget { } class _SearchFoodComponentState extends State { - StatisticsService statisticsService = StatisticsService(); void storeFood() async { - statisticsService.addItemToMainBox(widget.food, widget.cardName); - final todayBox = Hive.box(dotenv.env['TODAY_BOX']!); - if (!todayBox.isOpen){ - Hive.openBox(dotenv.env['TODAY_BOX']!); + StatisticsService.instance.addItemToMainBox(widget.food, widget.cardName); + final mealplanBox = Hive.box(dotenv.env['MEALPLAN_BOX']!); + if (!mealplanBox.isOpen){ + Hive.openBox(dotenv.env['MEALPLAN_BOX']!); } - addValuesToList(todayBox, widget.cardName, [widget.food]); + addValuesToList(mealplanBox, widget.cardName, [widget.food]); } void addValuesToList(box, String key, List newValues){ diff --git a/lib/android/components/meal_page_text/days_component.dart b/lib/android/components/meal_page_text/days_component.dart index 0a321a6..00451e3 100644 --- a/lib/android/components/meal_page_text/days_component.dart +++ b/lib/android/components/meal_page_text/days_component.dart @@ -18,17 +18,16 @@ class DaysMealPageComponent extends StatefulWidget { class _DaysMealPageState extends State { int activatedIndex = 0; - StatisticsService statisticsService = StatisticsService(); void updateValue(int index) { setState(() { activatedIndex = index; if(activatedIndex == 0){ - statisticsService.updateReducedBoxByTimespan(TimeSpan.day); + StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day); }else if(activatedIndex == 1){ - statisticsService.updateReducedBoxByTimespan(TimeSpan.week); + StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.week); }else if(activatedIndex == 2){ - statisticsService.updateReducedBoxByTimespan(TimeSpan.month); + StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.month); } }); } diff --git a/lib/android/config/setup_todaybox_config.dart b/lib/android/config/setup_todaybox_config.dart index 5c62ef1..36d3734 100644 --- a/lib/android/config/setup_todaybox_config.dart +++ b/lib/android/config/setup_todaybox_config.dart @@ -7,7 +7,7 @@ final List emptyList = []; void setupTodayBox() async{ - final todayBox = Hive.box(dotenv.env['TODAY_BOX']!); + final todayBox = Hive.box(dotenv.env['MEALPLAN_BOX']!); putIfKeyNotExists(todayBox, 'FRÜHSTÜCK', []); putIfKeyNotExists(todayBox, 'MITTAGESSEN', []); putIfKeyNotExists(todayBox, 'ABENDESSEN', []); diff --git a/lib/android/config/statistics.dart b/lib/android/config/statistics.dart index 87291c3..4fa2117 100644 --- a/lib/android/config/statistics.dart +++ b/lib/android/config/statistics.dart @@ -1,7 +1,9 @@ import 'dart:math'; import 'package:ernaehrung/android/components/meal_page_text/days_component.dart'; import 'package:ernaehrung/android/config/cast_helper.dart'; -import 'package:flutter/cupertino.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive/hive.dart'; import '../models/food.dart'; import 'format_helper.dart'; @@ -16,19 +18,18 @@ class StatisticsService { StatisticsService._internal() { initBoxes(); } + final String todayStatisticsBoxName = dotenv.env['STATISTICS_TODAY_BOX'] ?? 'STATISTICS_TODAY_BOX'; + final String mainStatisticsBoxName = dotenv.env['STATISTICS_MAIN_BOX'] ?? 'STATISTICS_MAIN_BOX'; + final String progressStatisticsBoxName = dotenv.env['STATISTICS_PROGRESS_BOX'] ?? 'STATISTICS_PROGRESS_BOX'; - final String reducedStatisticsBoxName = 'STATISTICS_REDUCED'; - final String mainStatisticsBoxName = 'STATISTICS_MAIN'; - final String progressStatisticsBoxName = 'STATISTICS_PROGRESS'; ValueNotifier eatenCalories = ValueNotifier(0); ValueNotifier> ingredients = ValueNotifier>([0,0,0]); ValueNotifier dailyAverageForCurrentWeek = ValueNotifier(0); ValueNotifier> weeklyCaloryRanking = ValueNotifier>([]); - - + ValueNotifier> barChartData = ValueNotifier>([]); initBoxes()async{ - Box reducedBox = Hive.box(reducedStatisticsBoxName); + Box reducedBox = Hive.box(todayStatisticsBoxName); Box progressBox = Hive.box(progressStatisticsBoxName); putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []); @@ -50,18 +51,18 @@ class StatisticsService { int timestamp = getTimestampFromNow(); switch(timeSpan){ case TimeSpan.day: - getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(reducedStatisticsBoxName)); + getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName)); break; case TimeSpan.week: List currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp); for(int i = 0;i < currentWeek.length;i++){ - getNewFoodAndUpdateBoxByTimestampAndBox(currentWeek[i],Hive.box(reducedStatisticsBoxName)); + getNewFoodAndUpdateBoxByTimestampAndBox(currentWeek[i],Hive.box(todayStatisticsBoxName)); } break; case TimeSpan.month: List currentMonth = getTimestampsByTimestampAndTimespan(TimeSpan.month,timestamp); for(int i = 0;i < currentMonth.length;i++){ - getNewFoodAndUpdateBoxByTimestampAndBox(currentMonth[i],Hive.box(reducedStatisticsBoxName)); + getNewFoodAndUpdateBoxByTimestampAndBox(currentMonth[i],Hive.box(todayStatisticsBoxName)); } break; } @@ -69,7 +70,7 @@ class StatisticsService { } void updateCalculationsAndNotfiyListenersForPorgressStatistics(){ - eatenCalories.value = getAllEatenCaloriesByBox(Hive.box(reducedStatisticsBoxName)); + eatenCalories.value = getAllEatenCaloriesByBox(Hive.box(todayStatisticsBoxName)); eatenCalories.notifyListeners(); ingredients.value = getAllEatenIngredientsForTodayStatistics(); ingredients.notifyListeners(); @@ -99,7 +100,7 @@ class StatisticsService { } clearReducedBoxBeforeUpdate(){ - Box box = Hive.box(reducedStatisticsBoxName); + Box box = Hive.box(todayStatisticsBoxName); for(int i = 0; i < box.keys.length;i++){ box.put(box.keys.elementAt(i), []); } @@ -121,14 +122,14 @@ class StatisticsService { Map> getFoodMapForGivenTimestampFromMainBox(int timestamp){ Box box = Hive.box(mainStatisticsBoxName); - dynamic matchingTimestamp = getMatchingTimeStamp(box, timestamp); + dynamic matchingTimestamp = getMatchingTimestamp(box, timestamp); if(matchingTimestamp != null){ return castDynamicMap(box.get(matchingTimestamp)); } return >{}; } - getMatchingTimeStamp(Box box,int newTimestamp){ + getMatchingTimestamp(Box box,int newTimestamp){ if(box.keys.isNotEmpty){ for(int i = 0; i < box.keys.length;i++){ int timestamp = box.keys.elementAt(i); @@ -167,7 +168,7 @@ class StatisticsService { int newTimestamp = dateTime.millisecondsSinceEpoch.toInt() ~/ 1000; - dynamic matchingTimestamp = getMatchingTimeStamp(box, newTimestamp); + dynamic matchingTimestamp = getMatchingTimestamp(box, newTimestamp); if(matchingTimestamp != null){ newTimestamp = matchingTimestamp; } @@ -204,7 +205,7 @@ class StatisticsService { } List getAllEatenIngredientsForTodayStatistics(){ - Box box = Hive.box(reducedStatisticsBoxName); + Box box = Hive.box(todayStatisticsBoxName); num fat = 0; num protein = 0; num carbs = 0; @@ -223,6 +224,8 @@ class StatisticsService { dailyAverageForCurrentWeek.notifyListeners(); weeklyCaloryRanking.value = getWeeklyCaloryRanking(); weeklyCaloryRanking.notifyListeners(); + barChartData.value = getBarChartData(); + barChartData.notifyListeners(); } void updateProgressBoxValues(){ @@ -258,6 +261,165 @@ class StatisticsService { return getListOfDistinctElements(allFoodsOfWeek); } + int getSumOfCaloriesByFoodList(List foods){ + int sum = 0; + for(int i = 0; i < foods.length;i++){ + sum += foods[i].calories as int; + } + return sum; + } + + List getBarChartData(){ + int timestamp = getTimestampFromNow(); + List currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp); + int maxValue = 0; + List> result = + [ + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + ]; //[[breakfast,lunch,dinner],[breakfast,lunch,dinner] ...] + for(int i = 0;i < currentWeek.length;i++){ + Map> foodMapFromMainBoxByTimestamp = getFoodMapForGivenTimestampFromMainBox(currentWeek[i]); + Iterable keys = foodMapFromMainBoxByTimestamp.keys; + if(keys.isNotEmpty){ + for(int j = 0; j < keys.length;j++){ + int value = getSumOfCaloriesByFoodList(foodMapFromMainBoxByTimestamp[keys.elementAt(j)] ?? []); + if(value > maxValue){ + maxValue = value; + } + + result[i][j] = (value * 175) ~/ 100; + } + } + } + return [ + BarChartGroupData( + x: 0, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[0][0].toDouble(), // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[0][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[0][2].toDouble(), // Second segment color + ),], + showingTooltipIndicators: [0], + groupVertically: true + ), + BarChartGroupData( + x: 1, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[1][0].toDouble(), + // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[1][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[1][2].toDouble(), // Second segment color + ),], + showingTooltipIndicators: [0], + ), + BarChartGroupData( + x: 2, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[2][0].toDouble(), // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[2][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[2][2].toDouble(), // Second segment color + ),], + showingTooltipIndicators: [0], + ), + BarChartGroupData( + x: 3, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[3][0].toDouble(), // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[3][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[3][2].toDouble(), // Second segment color + ),], + showingTooltipIndicators: [0], + ), + BarChartGroupData( + x: 4, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[4][0].toDouble(), // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[4][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[4][2].toDouble(), // Second segment color + ),], + showingTooltipIndicators: [0], + ), + BarChartGroupData( + x: 5, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[5][0].toDouble(), // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[5][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[5][2].toDouble(), // Second segment color + ),], showingTooltipIndicators: [0], + ), + BarChartGroupData( + x: 6, + barRods: [BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.yellow, + toY: result[6][0].toDouble(), // First segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.red, + toY: result[6][1].toDouble(), // Second segment color + ), BarChartRodData( + width: 7.5, // Adjust the width of the bar if needed + color: Colors.green, + toY: result[6][2].toDouble(), // Second segment color + ),], showingTooltipIndicators: [0], + ), + ]; + } + getTimestampFromNow(){ DateTime now = DateTime.now(); return now.millisecondsSinceEpoch.toInt() ~/ 1000; diff --git a/lib/android/pages/nav_pages/progress_page.dart b/lib/android/pages/nav_pages/progress_page.dart index 287626b..9d6479f 100644 --- a/lib/android/pages/nav_pages/progress_page.dart +++ b/lib/android/pages/nav_pages/progress_page.dart @@ -48,6 +48,19 @@ class ProgressPage extends StatelessWidget { ), const SecondaryTextComponent("Durchschnittlich"), SecondaryBigTextComponent(value.toString()), + ], + ), + ); + }, + ), + ValueListenableBuilder( + valueListenable: StatisticsService.instance.barChartData, + builder: (context, value, child) { + return SizedBox( + height: 205, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ SizedBox( height: 200, child: BarChart( @@ -55,7 +68,7 @@ class ProgressPage extends StatelessWidget { barTouchData: barTouchData, titlesData: titlesData, borderData: borderData, - barGroups: barGroups, + barGroups: value, gridData: FlGridData(show: false), alignment: BarChartAlignment.spaceAround, maxY: 200, @@ -127,25 +140,25 @@ class ProgressPage extends StatelessWidget { String text; switch (value.toInt()) { case 0: - text = 'Mn'; + text = 'M'; break; case 1: - text = 'Te'; + text = 'T'; break; case 2: - text = 'Wd'; + text = 'W'; break; case 3: - text = 'Tu'; + text = 'T'; break; case 4: - text = 'Fr'; + text = 'F'; break; case 5: - text = 'St'; + text = 'S'; break; case 6: - text = 'Sn'; + text = 'S'; break; default: text = ''; @@ -182,85 +195,4 @@ class ProgressPage extends StatelessWidget { show: false, ); - LinearGradient get _barsGradient => const LinearGradient( - colors: [ - Colors.cyan, - Colors.deepPurple, - ], - begin: Alignment.bottomCenter, - end: Alignment.topCenter, - ); - - List get barGroups => [ - BarChartGroupData( - x: 0, - barRods: [ - BarChartRodData( - toY: 8, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - BarChartGroupData( - x: 1, - barRods: [ - BarChartRodData( - toY: 10, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - BarChartGroupData( - x: 2, - barRods: [ - BarChartRodData( - toY: 14, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - BarChartGroupData( - x: 3, - barRods: [ - BarChartRodData( - toY: 150, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - BarChartGroupData( - x: 4, - barRods: [ - BarChartRodData( - toY: 13, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - BarChartGroupData( - x: 5, - barRods: [ - BarChartRodData( - toY: 10, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - BarChartGroupData( - x: 6, - barRods: [ - BarChartRodData( - toY: 16, - gradient: _barsGradient, - ) - ], - showingTooltipIndicators: [0], - ), - ]; } diff --git a/lib/android/pages/nav_pages/today_page.dart b/lib/android/pages/nav_pages/today_page.dart index 6b76bb3..34e39e0 100644 --- a/lib/android/pages/nav_pages/today_page.dart +++ b/lib/android/pages/nav_pages/today_page.dart @@ -1,5 +1,6 @@ import 'package:ernaehrung/android/components/card/card_component.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:hive_flutter/adapters.dart'; class TodayPage extends StatefulWidget { @@ -18,7 +19,7 @@ class _TodayPageState extends State { return Scaffold( body: SingleChildScrollView( child: ValueListenableBuilder( - valueListenable: Hive.box("TODAY").listenable(), + valueListenable: Hive.box(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN').listenable(), builder: (context, box, widget) { return ListView.builder( primary: false, diff --git a/lib/main.dart b/lib/main.dart index 48fd8b8..21dacec 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,9 +5,9 @@ import 'package:hive_flutter/hive_flutter.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'android/andoird_app.dart'; import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb; - import 'android/config/setup_todaybox_config.dart'; + void main() async { await dotenv.load(fileName: ".env"); await Hive.initFlutter(); @@ -17,10 +17,11 @@ void main() async { } //await Hive.deleteFromDisk(); - await Hive.openBox('STATISTICS_REDUCED'); - await Hive.openBox('STATISTICS_PROGRESS'); - await Hive.openBox('STATISTICS_MAIN'); - await Hive.openBox('TODAY'); + await Hive.openBox(dotenv.env['STATISTICS_TODAY_BOX'] ?? 'STATISTICS_TODAY_BOX'); + await Hive.openBox( dotenv.env['STATISTICS_PROGRESS_BOX'] ?? 'STATISTICS_PROGRESS_BOX'); + await Hive.openBox(dotenv.env['STATISTICS_MAIN_BOX'] ?? 'STATISTICS_MAIN_BOX'); + await Hive.openBox(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN'); + setupTodayBox(); //Hive.deleteFromDisk();