feat: show only food list from today on today page

pull/4/head
98spag 2023-06-01 13:59:12 +02:00
parent 8d33371966
commit 795de496cd
4 changed files with 21 additions and 18 deletions

View File

@ -23,11 +23,11 @@ class _DaysMealPageState extends State<DaysMealPageComponent> {
setState(() { setState(() {
activatedIndex = index; activatedIndex = index;
if(activatedIndex == 0){ if(activatedIndex == 0){
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day); StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
}else if(activatedIndex == 1){ }else if(activatedIndex == 1){
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.week); StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.week);
}else if(activatedIndex == 2){ }else if(activatedIndex == 2){
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.month); StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.month);
} }
}); });
} }

View File

@ -35,7 +35,7 @@ class StatisticsService {
putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []); putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []);
putIfKeyNotExists([reducedBox,progressBox], 'MITTAGESSEN', []); putIfKeyNotExists([reducedBox,progressBox], 'MITTAGESSEN', []);
putIfKeyNotExists([reducedBox,progressBox], 'ABENDESSEN', []); putIfKeyNotExists([reducedBox,progressBox], 'ABENDESSEN', []);
updateReducedBoxByTimespan(TimeSpan.day); updateStatisticsTodayBoxByTimespan(TimeSpan.day);
} }
void putIfKeyNotExists(List<Box> boxes, String key, dynamic value) { void putIfKeyNotExists(List<Box> boxes, String key, dynamic value) {
@ -46,10 +46,10 @@ class StatisticsService {
} }
} }
updateReducedBoxByTimespan(TimeSpan timeSpan){ updateStatisticsTodayBoxByTimespan(TimeSpan timespan){
clearReducedBoxBeforeUpdate(); clearBoxByBox(Hive.box(todayStatisticsBoxName));
int timestamp = getTimestampFromNow(); int timestamp = getTimestampFromNow();
switch(timeSpan){ switch(timespan){
case TimeSpan.day: case TimeSpan.day:
getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName)); getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName));
break; break;
@ -99,8 +99,7 @@ class StatisticsService {
return timestampsForWeekdays; return timestampsForWeekdays;
} }
clearReducedBoxBeforeUpdate(){ clearBoxByBox(Box box){
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), []);
} }
@ -419,6 +418,12 @@ class StatisticsService {
return now.millisecondsSinceEpoch.toInt() ~/ 1000; return now.millisecondsSinceEpoch.toInt() ~/ 1000;
} }
List<Food> getMealsOfTodayByMealtype(String mealtype){
int timestamp = getTimestampFromNow();
return getFoodMapForGivenTimestampFromMainBox(timestamp)[mealtype] ?? [];
}
showItems(){ showItems(){
print("Statistics.dart - showItems() - ITEMS"); print("Statistics.dart - showItems() - ITEMS");
//Hive.box(boxName).clear(); //Hive.box(boxName).clear();

View File

@ -25,7 +25,7 @@ class MainPageState extends State<MainPage> {
setState(() { setState(() {
currentIndex = index; currentIndex = index;
if(currentIndex == 1){ if(currentIndex == 1){
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day); StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
}else if(currentIndex == 2){ }else if(currentIndex == 2){
StatisticsService.instance.updateProgressBoxValues(); StatisticsService.instance.updateProgressBoxValues();
} }

View File

@ -1,4 +1,5 @@
import 'package:ernaehrung/android/components/card/card_component.dart'; import 'package:ernaehrung/android/components/card/card_component.dart';
import 'package:ernaehrung/android/config/statistics.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive_flutter/adapters.dart'; import 'package:hive_flutter/adapters.dart';
@ -26,14 +27,11 @@ class _TodayPageState extends State<TodayPage> {
shrinkWrap: true, shrinkWrap: true,
itemCount: box.keys.length, itemCount: box.keys.length,
itemBuilder: (context, i) { itemBuilder: (context, i) {
if (box.keyAt(i).toString() == "DATE") { String mealTypeAsString = box.keyAt(i).toString();
return const SizedBox.shrink(); return CardComponent(
} else { mealTypeAsString,
return CardComponent( StatisticsService.instance.getMealsOfTodayByMealtype(mealTypeAsString)
box.keyAt(i).toString(), );
box.getAt(i)
);
}
}); });
}))); })));
} }