feat: adjustments
parent
fcc607043e
commit
f25de45f7c
|
@ -584,7 +584,7 @@
|
||||||
"languageVersion": "2.19"
|
"languageVersion": "2.19"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"generated": "2023-05-30T14:26:53.205127Z",
|
"generated": "2023-06-01T10:00:31.814419Z",
|
||||||
"generator": "pub",
|
"generator": "pub",
|
||||||
"generatorVersion": "3.0.2"
|
"generatorVersion": "3.0.2"
|
||||||
}
|
}
|
||||||
|
|
7
.env
7
.env
|
@ -4,10 +4,15 @@ SECOND_NAME_FIELD=SECOND_NAME
|
||||||
WEIGHT_FIELD=WEIGHT
|
WEIGHT_FIELD=WEIGHT
|
||||||
HEIGHT_FIELD=HEIGHT
|
HEIGHT_FIELD=HEIGHT
|
||||||
CALORIES_FIELD=CALORIES
|
CALORIES_FIELD=CALORIES
|
||||||
TODAY_BOX=TODAY
|
|
||||||
DATE_FIELD=DATE # datum
|
DATE_FIELD=DATE # datum
|
||||||
BREAKFAST_FIELD=FRÜHSTÜCK # frühstück
|
BREAKFAST_FIELD=FRÜHSTÜCK # frühstück
|
||||||
LUNCH_FIELD=MITTAGESSEN # mittagessen
|
LUNCH_FIELD=MITTAGESSEN # mittagessen
|
||||||
DINNER_FIELD=ABENDESSEN # abendessen
|
DINNER_FIELD=ABENDESSEN # abendessen
|
||||||
YESTERDAY_AND_BEFORE=YESTERDAY # gestern und alles was davor war
|
YESTERDAY_AND_BEFORE=YESTERDAY # gestern und alles was davor war
|
||||||
TOMORROW_AND_AFTER=TOMORROW # morgen und alles was kommen wird
|
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
|
|
@ -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"}
|
{"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"}
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:ernaehrung/android/components/food_list_component.dart';
|
import 'package:ernaehrung/android/components/food_list_component.dart';
|
||||||
|
import 'package:ernaehrung/android/config/statistics.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'meal_page_text/title_component.dart';
|
import 'meal_page_text/title_component.dart';
|
||||||
|
@ -19,7 +20,7 @@ class MealPageStatisticsFoodComponent extends StatelessWidget {
|
||||||
height: 24,
|
height: 24,
|
||||||
),
|
),
|
||||||
const TitleComponent("Nahrung"),
|
const TitleComponent("Nahrung"),
|
||||||
FoodComponent(box: Hive.box('STATISTICS_REDUCED'),)
|
FoodComponent(box: Hive.box(StatisticsService.instance.todayStatisticsBoxName),)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import 'package:basic_utils/basic_utils.dart';
|
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_data_food_component.dart';
|
||||||
import 'package:ernaehrung/android/components/card/card_title_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 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../models/food.dart';
|
|
||||||
import '../../pages/nav_pages/search_food.dart';
|
import '../../pages/nav_pages/search_food.dart';
|
||||||
|
|
||||||
class CardComponent extends StatelessWidget {
|
class CardComponent extends StatelessWidget {
|
||||||
|
@ -12,14 +11,6 @@ class CardComponent extends StatelessWidget {
|
||||||
|
|
||||||
const CardComponent(this.title, this.foods, {super.key});
|
const CardComponent(this.title, this.foods, {super.key});
|
||||||
|
|
||||||
List<Food> castDynamicToListFood(List<dynamic> dynamicList) {
|
|
||||||
List<Food> foodList = [];
|
|
||||||
for (Food element in dynamicList) {
|
|
||||||
foodList.add(element);
|
|
||||||
}
|
|
||||||
return foodList;
|
|
||||||
}
|
|
||||||
|
|
||||||
Route createRoute(String cardName) {
|
Route createRoute(String cardName) {
|
||||||
return PageRouteBuilder(
|
return PageRouteBuilder(
|
||||||
pageBuilder: (context, animation, secondaryAnimation) =>
|
pageBuilder: (context, animation, secondaryAnimation) =>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:ernaehrung/android/config/cast_helper.dart';
|
import 'package:ernaehrung/android/config/cast_helper.dart';
|
||||||
|
import 'package:ernaehrung/android/config/statistics.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:hive_flutter/adapters.dart';
|
import 'package:hive_flutter/adapters.dart';
|
||||||
import 'card_component.dart';
|
import 'card_component.dart';
|
||||||
|
@ -24,7 +25,7 @@ class FoodComponent extends StatelessWidget {
|
||||||
return CardComponent(
|
return CardComponent(
|
||||||
eatingMealName: box.keyAt(i).toString(),
|
eatingMealName: box.keyAt(i).toString(),
|
||||||
selectedMeal: castDynamicToListFood(box.getAt(i)),
|
selectedMeal: castDynamicToListFood(box.getAt(i)),
|
||||||
addButtonVisible: box.name != 'statistics_reduced',
|
addButtonVisible: box.name != StatisticsService.instance.todayStatisticsBoxName.toLowerCase(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,15 +16,14 @@ class SearchedFoodComponent extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SearchFoodComponentState extends State<SearchedFoodComponent> {
|
class _SearchFoodComponentState extends State<SearchedFoodComponent> {
|
||||||
StatisticsService statisticsService = StatisticsService();
|
|
||||||
|
|
||||||
void storeFood() async {
|
void storeFood() async {
|
||||||
statisticsService.addItemToMainBox(widget.food, widget.cardName);
|
StatisticsService.instance.addItemToMainBox(widget.food, widget.cardName);
|
||||||
final todayBox = Hive.box(dotenv.env['TODAY_BOX']!);
|
final mealplanBox = Hive.box(dotenv.env['MEALPLAN_BOX']!);
|
||||||
if (!todayBox.isOpen){
|
if (!mealplanBox.isOpen){
|
||||||
Hive.openBox(dotenv.env['TODAY_BOX']!);
|
Hive.openBox(dotenv.env['MEALPLAN_BOX']!);
|
||||||
}
|
}
|
||||||
addValuesToList(todayBox, widget.cardName, [widget.food]);
|
addValuesToList(mealplanBox, widget.cardName, [widget.food]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addValuesToList(box, String key, List<Food> newValues){
|
void addValuesToList(box, String key, List<Food> newValues){
|
||||||
|
|
|
@ -18,17 +18,16 @@ class DaysMealPageComponent extends StatefulWidget {
|
||||||
|
|
||||||
class _DaysMealPageState extends State<DaysMealPageComponent> {
|
class _DaysMealPageState extends State<DaysMealPageComponent> {
|
||||||
int activatedIndex = 0;
|
int activatedIndex = 0;
|
||||||
StatisticsService statisticsService = StatisticsService();
|
|
||||||
|
|
||||||
void updateValue(int index) {
|
void updateValue(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
activatedIndex = index;
|
activatedIndex = index;
|
||||||
if(activatedIndex == 0){
|
if(activatedIndex == 0){
|
||||||
statisticsService.updateReducedBoxByTimespan(TimeSpan.day);
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day);
|
||||||
}else if(activatedIndex == 1){
|
}else if(activatedIndex == 1){
|
||||||
statisticsService.updateReducedBoxByTimespan(TimeSpan.week);
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.week);
|
||||||
}else if(activatedIndex == 2){
|
}else if(activatedIndex == 2){
|
||||||
statisticsService.updateReducedBoxByTimespan(TimeSpan.month);
|
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.month);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ final List<Food> emptyList = [];
|
||||||
|
|
||||||
|
|
||||||
void setupTodayBox() async{
|
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, 'FRÜHSTÜCK', []);
|
||||||
putIfKeyNotExists(todayBox, 'MITTAGESSEN', []);
|
putIfKeyNotExists(todayBox, 'MITTAGESSEN', []);
|
||||||
putIfKeyNotExists(todayBox, 'ABENDESSEN', []);
|
putIfKeyNotExists(todayBox, 'ABENDESSEN', []);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'package:ernaehrung/android/components/meal_page_text/days_component.dart';
|
import 'package:ernaehrung/android/components/meal_page_text/days_component.dart';
|
||||||
import 'package:ernaehrung/android/config/cast_helper.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 'package:hive/hive.dart';
|
||||||
import '../models/food.dart';
|
import '../models/food.dart';
|
||||||
import 'format_helper.dart';
|
import 'format_helper.dart';
|
||||||
|
@ -16,19 +18,18 @@ class StatisticsService {
|
||||||
StatisticsService._internal() {
|
StatisticsService._internal() {
|
||||||
initBoxes();
|
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<int> eatenCalories = ValueNotifier<int>(0);
|
ValueNotifier<int> eatenCalories = ValueNotifier<int>(0);
|
||||||
ValueNotifier<List<double>> ingredients = ValueNotifier<List<double>>([0,0,0]);
|
ValueNotifier<List<double>> ingredients = ValueNotifier<List<double>>([0,0,0]);
|
||||||
ValueNotifier<int> dailyAverageForCurrentWeek = ValueNotifier<int>(0);
|
ValueNotifier<int> dailyAverageForCurrentWeek = ValueNotifier<int>(0);
|
||||||
ValueNotifier<List<Food>> weeklyCaloryRanking = ValueNotifier<List<Food>>([]);
|
ValueNotifier<List<Food>> weeklyCaloryRanking = ValueNotifier<List<Food>>([]);
|
||||||
|
ValueNotifier<List<BarChartGroupData>> barChartData = ValueNotifier<List<BarChartGroupData>>([]);
|
||||||
|
|
||||||
|
|
||||||
initBoxes()async{
|
initBoxes()async{
|
||||||
Box reducedBox = Hive.box(reducedStatisticsBoxName);
|
Box reducedBox = Hive.box(todayStatisticsBoxName);
|
||||||
Box progressBox = Hive.box(progressStatisticsBoxName);
|
Box progressBox = Hive.box(progressStatisticsBoxName);
|
||||||
|
|
||||||
putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []);
|
putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []);
|
||||||
|
@ -50,18 +51,18 @@ class StatisticsService {
|
||||||
int timestamp = getTimestampFromNow();
|
int timestamp = getTimestampFromNow();
|
||||||
switch(timeSpan){
|
switch(timeSpan){
|
||||||
case TimeSpan.day:
|
case TimeSpan.day:
|
||||||
getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(reducedStatisticsBoxName));
|
getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName));
|
||||||
break;
|
break;
|
||||||
case TimeSpan.week:
|
case TimeSpan.week:
|
||||||
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
||||||
for(int i = 0;i < currentWeek.length;i++){
|
for(int i = 0;i < currentWeek.length;i++){
|
||||||
getNewFoodAndUpdateBoxByTimestampAndBox(currentWeek[i],Hive.box(reducedStatisticsBoxName));
|
getNewFoodAndUpdateBoxByTimestampAndBox(currentWeek[i],Hive.box(todayStatisticsBoxName));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TimeSpan.month:
|
case TimeSpan.month:
|
||||||
List<int> currentMonth = getTimestampsByTimestampAndTimespan(TimeSpan.month,timestamp);
|
List<int> currentMonth = getTimestampsByTimestampAndTimespan(TimeSpan.month,timestamp);
|
||||||
for(int i = 0;i < currentMonth.length;i++){
|
for(int i = 0;i < currentMonth.length;i++){
|
||||||
getNewFoodAndUpdateBoxByTimestampAndBox(currentMonth[i],Hive.box(reducedStatisticsBoxName));
|
getNewFoodAndUpdateBoxByTimestampAndBox(currentMonth[i],Hive.box(todayStatisticsBoxName));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ class StatisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateCalculationsAndNotfiyListenersForPorgressStatistics(){
|
void updateCalculationsAndNotfiyListenersForPorgressStatistics(){
|
||||||
eatenCalories.value = getAllEatenCaloriesByBox(Hive.box(reducedStatisticsBoxName));
|
eatenCalories.value = getAllEatenCaloriesByBox(Hive.box(todayStatisticsBoxName));
|
||||||
eatenCalories.notifyListeners();
|
eatenCalories.notifyListeners();
|
||||||
ingredients.value = getAllEatenIngredientsForTodayStatistics();
|
ingredients.value = getAllEatenIngredientsForTodayStatistics();
|
||||||
ingredients.notifyListeners();
|
ingredients.notifyListeners();
|
||||||
|
@ -99,7 +100,7 @@ class StatisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearReducedBoxBeforeUpdate(){
|
clearReducedBoxBeforeUpdate(){
|
||||||
Box box = Hive.box(reducedStatisticsBoxName);
|
Box box = Hive.box(todayStatisticsBoxName);
|
||||||
for(int i = 0; i < box.keys.length;i++){
|
for(int i = 0; i < box.keys.length;i++){
|
||||||
box.put(box.keys.elementAt(i), []);
|
box.put(box.keys.elementAt(i), []);
|
||||||
}
|
}
|
||||||
|
@ -121,14 +122,14 @@ class StatisticsService {
|
||||||
|
|
||||||
Map<String,List<Food>> getFoodMapForGivenTimestampFromMainBox(int timestamp){
|
Map<String,List<Food>> getFoodMapForGivenTimestampFromMainBox(int timestamp){
|
||||||
Box box = Hive.box(mainStatisticsBoxName);
|
Box box = Hive.box(mainStatisticsBoxName);
|
||||||
dynamic matchingTimestamp = getMatchingTimeStamp(box, timestamp);
|
dynamic matchingTimestamp = getMatchingTimestamp(box, timestamp);
|
||||||
if(matchingTimestamp != null){
|
if(matchingTimestamp != null){
|
||||||
return castDynamicMap(box.get(matchingTimestamp));
|
return castDynamicMap(box.get(matchingTimestamp));
|
||||||
}
|
}
|
||||||
return <String,List<Food>>{};
|
return <String,List<Food>>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
getMatchingTimeStamp(Box box,int newTimestamp){
|
getMatchingTimestamp(Box box,int newTimestamp){
|
||||||
if(box.keys.isNotEmpty){
|
if(box.keys.isNotEmpty){
|
||||||
for(int i = 0; i < box.keys.length;i++){
|
for(int i = 0; i < box.keys.length;i++){
|
||||||
int timestamp = box.keys.elementAt(i);
|
int timestamp = box.keys.elementAt(i);
|
||||||
|
@ -167,7 +168,7 @@ class StatisticsService {
|
||||||
|
|
||||||
int newTimestamp = dateTime.millisecondsSinceEpoch.toInt() ~/ 1000;
|
int newTimestamp = dateTime.millisecondsSinceEpoch.toInt() ~/ 1000;
|
||||||
|
|
||||||
dynamic matchingTimestamp = getMatchingTimeStamp(box, newTimestamp);
|
dynamic matchingTimestamp = getMatchingTimestamp(box, newTimestamp);
|
||||||
if(matchingTimestamp != null){
|
if(matchingTimestamp != null){
|
||||||
newTimestamp = matchingTimestamp;
|
newTimestamp = matchingTimestamp;
|
||||||
}
|
}
|
||||||
|
@ -204,7 +205,7 @@ class StatisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<double> getAllEatenIngredientsForTodayStatistics(){
|
List<double> getAllEatenIngredientsForTodayStatistics(){
|
||||||
Box box = Hive.box(reducedStatisticsBoxName);
|
Box box = Hive.box(todayStatisticsBoxName);
|
||||||
num fat = 0;
|
num fat = 0;
|
||||||
num protein = 0;
|
num protein = 0;
|
||||||
num carbs = 0;
|
num carbs = 0;
|
||||||
|
@ -223,6 +224,8 @@ class StatisticsService {
|
||||||
dailyAverageForCurrentWeek.notifyListeners();
|
dailyAverageForCurrentWeek.notifyListeners();
|
||||||
weeklyCaloryRanking.value = getWeeklyCaloryRanking();
|
weeklyCaloryRanking.value = getWeeklyCaloryRanking();
|
||||||
weeklyCaloryRanking.notifyListeners();
|
weeklyCaloryRanking.notifyListeners();
|
||||||
|
barChartData.value = getBarChartData();
|
||||||
|
barChartData.notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateProgressBoxValues(){
|
void updateProgressBoxValues(){
|
||||||
|
@ -258,6 +261,165 @@ class StatisticsService {
|
||||||
return getListOfDistinctElements(allFoodsOfWeek);
|
return getListOfDistinctElements(allFoodsOfWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getSumOfCaloriesByFoodList(List<Food> foods){
|
||||||
|
int sum = 0;
|
||||||
|
for(int i = 0; i < foods.length;i++){
|
||||||
|
sum += foods[i].calories as int;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BarChartGroupData> getBarChartData(){
|
||||||
|
int timestamp = getTimestampFromNow();
|
||||||
|
List<int> currentWeek = getTimestampsByTimestampAndTimespan(TimeSpan.week,timestamp);
|
||||||
|
int maxValue = 0;
|
||||||
|
List<List<int>> 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<String,List<Food>> foodMapFromMainBoxByTimestamp = getFoodMapForGivenTimestampFromMainBox(currentWeek[i]);
|
||||||
|
Iterable<String> 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(){
|
getTimestampFromNow(){
|
||||||
DateTime now = DateTime.now();
|
DateTime now = DateTime.now();
|
||||||
return now.millisecondsSinceEpoch.toInt() ~/ 1000;
|
return now.millisecondsSinceEpoch.toInt() ~/ 1000;
|
||||||
|
|
|
@ -48,6 +48,19 @@ class ProgressPage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const SecondaryTextComponent("Durchschnittlich"),
|
const SecondaryTextComponent("Durchschnittlich"),
|
||||||
SecondaryBigTextComponent(value.toString()),
|
SecondaryBigTextComponent(value.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ValueListenableBuilder(
|
||||||
|
valueListenable: StatisticsService.instance.barChartData,
|
||||||
|
builder: (context, value, child) {
|
||||||
|
return SizedBox(
|
||||||
|
height: 205,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
child: BarChart(
|
child: BarChart(
|
||||||
|
@ -55,7 +68,7 @@ class ProgressPage extends StatelessWidget {
|
||||||
barTouchData: barTouchData,
|
barTouchData: barTouchData,
|
||||||
titlesData: titlesData,
|
titlesData: titlesData,
|
||||||
borderData: borderData,
|
borderData: borderData,
|
||||||
barGroups: barGroups,
|
barGroups: value,
|
||||||
gridData: FlGridData(show: false),
|
gridData: FlGridData(show: false),
|
||||||
alignment: BarChartAlignment.spaceAround,
|
alignment: BarChartAlignment.spaceAround,
|
||||||
maxY: 200,
|
maxY: 200,
|
||||||
|
@ -127,25 +140,25 @@ class ProgressPage extends StatelessWidget {
|
||||||
String text;
|
String text;
|
||||||
switch (value.toInt()) {
|
switch (value.toInt()) {
|
||||||
case 0:
|
case 0:
|
||||||
text = 'Mn';
|
text = 'M';
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
text = 'Te';
|
text = 'T';
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
text = 'Wd';
|
text = 'W';
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
text = 'Tu';
|
text = 'T';
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
text = 'Fr';
|
text = 'F';
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
text = 'St';
|
text = 'S';
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
text = 'Sn';
|
text = 'S';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
text = '';
|
text = '';
|
||||||
|
@ -182,85 +195,4 @@ class ProgressPage extends StatelessWidget {
|
||||||
show: false,
|
show: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
LinearGradient get _barsGradient => const LinearGradient(
|
|
||||||
colors: [
|
|
||||||
Colors.cyan,
|
|
||||||
Colors.deepPurple,
|
|
||||||
],
|
|
||||||
begin: Alignment.bottomCenter,
|
|
||||||
end: Alignment.topCenter,
|
|
||||||
);
|
|
||||||
|
|
||||||
List<BarChartGroupData> 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],
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:ernaehrung/android/components/card/card_component.dart';
|
import 'package:ernaehrung/android/components/card/card_component.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:hive_flutter/adapters.dart';
|
import 'package:hive_flutter/adapters.dart';
|
||||||
|
|
||||||
class TodayPage extends StatefulWidget {
|
class TodayPage extends StatefulWidget {
|
||||||
|
@ -18,7 +19,7 @@ class _TodayPageState extends State<TodayPage> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: ValueListenableBuilder(
|
child: ValueListenableBuilder(
|
||||||
valueListenable: Hive.box("TODAY").listenable(),
|
valueListenable: Hive.box(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN').listenable(),
|
||||||
builder: (context, box, widget) {
|
builder: (context, box, widget) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
primary: false,
|
primary: false,
|
||||||
|
|
|
@ -5,9 +5,9 @@ import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'android/andoird_app.dart';
|
import 'android/andoird_app.dart';
|
||||||
import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb;
|
import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb;
|
||||||
|
|
||||||
import 'android/config/setup_todaybox_config.dart';
|
import 'android/config/setup_todaybox_config.dart';
|
||||||
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
await dotenv.load(fileName: ".env");
|
await dotenv.load(fileName: ".env");
|
||||||
await Hive.initFlutter();
|
await Hive.initFlutter();
|
||||||
|
@ -17,10 +17,11 @@ void main() async {
|
||||||
}
|
}
|
||||||
//await Hive.deleteFromDisk();
|
//await Hive.deleteFromDisk();
|
||||||
|
|
||||||
await Hive.openBox('STATISTICS_REDUCED');
|
await Hive.openBox(dotenv.env['STATISTICS_TODAY_BOX'] ?? 'STATISTICS_TODAY_BOX');
|
||||||
await Hive.openBox('STATISTICS_PROGRESS');
|
await Hive.openBox( dotenv.env['STATISTICS_PROGRESS_BOX'] ?? 'STATISTICS_PROGRESS_BOX');
|
||||||
await Hive.openBox('STATISTICS_MAIN');
|
await Hive.openBox(dotenv.env['STATISTICS_MAIN_BOX'] ?? 'STATISTICS_MAIN_BOX');
|
||||||
await Hive.openBox('TODAY');
|
await Hive.openBox(dotenv.env['MEALPLAN_BOX'] ?? 'MEALPLAN');
|
||||||
|
|
||||||
setupTodayBox();
|
setupTodayBox();
|
||||||
//Hive.deleteFromDisk();
|
//Hive.deleteFromDisk();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue