feat: show only food list from today on today page
parent
8d33371966
commit
795de496cd
|
@ -23,11 +23,11 @@ class _DaysMealPageState extends State<DaysMealPageComponent> {
|
|||
setState(() {
|
||||
activatedIndex = index;
|
||||
if(activatedIndex == 0){
|
||||
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day);
|
||||
StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
|
||||
}else if(activatedIndex == 1){
|
||||
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.week);
|
||||
StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.week);
|
||||
}else if(activatedIndex == 2){
|
||||
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.month);
|
||||
StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.month);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class StatisticsService {
|
|||
putIfKeyNotExists([reducedBox,progressBox], 'FRÜHSTÜCK', []);
|
||||
putIfKeyNotExists([reducedBox,progressBox], 'MITTAGESSEN', []);
|
||||
putIfKeyNotExists([reducedBox,progressBox], 'ABENDESSEN', []);
|
||||
updateReducedBoxByTimespan(TimeSpan.day);
|
||||
updateStatisticsTodayBoxByTimespan(TimeSpan.day);
|
||||
}
|
||||
|
||||
void putIfKeyNotExists(List<Box> boxes, String key, dynamic value) {
|
||||
|
@ -46,10 +46,10 @@ class StatisticsService {
|
|||
}
|
||||
}
|
||||
|
||||
updateReducedBoxByTimespan(TimeSpan timeSpan){
|
||||
clearReducedBoxBeforeUpdate();
|
||||
updateStatisticsTodayBoxByTimespan(TimeSpan timespan){
|
||||
clearBoxByBox(Hive.box(todayStatisticsBoxName));
|
||||
int timestamp = getTimestampFromNow();
|
||||
switch(timeSpan){
|
||||
switch(timespan){
|
||||
case TimeSpan.day:
|
||||
getNewFoodAndUpdateBoxByTimestampAndBox(timestamp, Hive.box(todayStatisticsBoxName));
|
||||
break;
|
||||
|
@ -99,8 +99,7 @@ class StatisticsService {
|
|||
return timestampsForWeekdays;
|
||||
}
|
||||
|
||||
clearReducedBoxBeforeUpdate(){
|
||||
Box box = Hive.box(todayStatisticsBoxName);
|
||||
clearBoxByBox(Box box){
|
||||
for(int i = 0; i < box.keys.length;i++){
|
||||
box.put(box.keys.elementAt(i), []);
|
||||
}
|
||||
|
@ -419,6 +418,12 @@ class StatisticsService {
|
|||
return now.millisecondsSinceEpoch.toInt() ~/ 1000;
|
||||
}
|
||||
|
||||
List<Food> getMealsOfTodayByMealtype(String mealtype){
|
||||
int timestamp = getTimestampFromNow();
|
||||
return getFoodMapForGivenTimestampFromMainBox(timestamp)[mealtype] ?? [];
|
||||
|
||||
}
|
||||
|
||||
showItems(){
|
||||
print("Statistics.dart - showItems() - ITEMS");
|
||||
//Hive.box(boxName).clear();
|
||||
|
|
|
@ -25,7 +25,7 @@ class MainPageState extends State<MainPage> {
|
|||
setState(() {
|
||||
currentIndex = index;
|
||||
if(currentIndex == 1){
|
||||
StatisticsService.instance.updateReducedBoxByTimespan(TimeSpan.day);
|
||||
StatisticsService.instance.updateStatisticsTodayBoxByTimespan(TimeSpan.day);
|
||||
}else if(currentIndex == 2){
|
||||
StatisticsService.instance.updateProgressBoxValues();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:ernaehrung/android/components/card/card_component.dart';
|
||||
import 'package:ernaehrung/android/config/statistics.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
|
@ -26,14 +27,11 @@ class _TodayPageState extends State<TodayPage> {
|
|||
shrinkWrap: true,
|
||||
itemCount: box.keys.length,
|
||||
itemBuilder: (context, i) {
|
||||
if (box.keyAt(i).toString() == "DATE") {
|
||||
return const SizedBox.shrink();
|
||||
} else {
|
||||
String mealTypeAsString = box.keyAt(i).toString();
|
||||
return CardComponent(
|
||||
box.keyAt(i).toString(),
|
||||
box.getAt(i)
|
||||
mealTypeAsString,
|
||||
StatisticsService.instance.getMealsOfTodayByMealtype(mealTypeAsString)
|
||||
);
|
||||
}
|
||||
});
|
||||
})));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue