bugfix: remove box contains check due to regulary cleaning box before update

welcome
98spag 2023-05-30 14:50:27 +02:00
parent 1f52c7971a
commit 722dff965b
2 changed files with 5 additions and 4 deletions

View File

@ -8,8 +8,11 @@ List<Food> castDynamicToListFood(List<dynamic> dynamicList) {
return foodList; return foodList;
} }
Map<String,List<Food>> castDynamicMap(Map<dynamic,dynamic> dynamicMap){ Map<String,List<Food>> castDynamicMap(dynamic dynamicMap){
Map<String,List<Food>> foodMap = {}; Map<String,List<Food>> foodMap = {};
if(dynamicMap == null){
return foodMap;
}
for(dynamic key in dynamicMap.keys){ for(dynamic key in dynamicMap.keys){
foodMap.putIfAbsent(key as String , () => castDynamicToListFood(dynamicMap[key])); foodMap.putIfAbsent(key as String , () => castDynamicToListFood(dynamicMap[key]));
} }

View File

@ -89,10 +89,8 @@ class StatisticsService {
void addValuesToList(Box box, String key, List<Food> newValues){ void addValuesToList(Box box, String key, List<Food> newValues){
List<Food> existingList = castDynamicToListFood(box.get(key)); List<Food> existingList = castDynamicToListFood(box.get(key));
for(int i = 0; i < newValues.length;i++){ for(int i = 0; i < newValues.length;i++){
if(!existingList.contains(newValues[i])){
existingList.add(newValues[i]); existingList.add(newValues[i]);
} }
}
box.put(key, existingList); box.put(key, existingList);
} }
@ -153,7 +151,7 @@ class StatisticsService {
if(matchingTimestamp != null){ if(matchingTimestamp != null){
newTimestamp = matchingTimestamp; newTimestamp = matchingTimestamp;
} }
Map<String, List<Food>>? valueMap = castDynamicMap(box.get(newTimestamp)); Map<String, List<Food>> valueMap = castDynamicMap(box.get(newTimestamp));
List<Food> values = []; List<Food> values = [];
if(valueMap.containsKey(mealType)){ if(valueMap.containsKey(mealType)){
values = valueMap[mealType]!; values = valueMap[mealType]!;