feat: add ingredient progress bars to page

feature/chart-progress-page
98spag 2023-05-30 17:28:16 +02:00
parent 77023ad118
commit b201a6758b
3 changed files with 27 additions and 8 deletions

View File

@ -5,28 +5,28 @@ import 'package:percent_indicator/linear_percent_indicator.dart';
class LineCircularWiTextComponent extends StatelessWidget {
final Color progressColor;
final double percent;
final int left;
final double value;
final int total;
final String textName;
const LineCircularWiTextComponent(
this.progressColor, this.percent, this.left, this.total, this.textName,
this.progressColor, this.value, this.total, this.textName,
{super.key});
@override
Widget build(BuildContext context) {
double progress = double.parse((value/total).toStringAsFixed(1));
return Padding(
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StaticsTextComponent(left.toString(), true),
StaticsTextComponent(double.parse(value.toString()).toStringAsFixed(2), true),
const SizedBox(height: 4,),
LinearPercentIndicator(
padding: EdgeInsets.zero,
lineHeight: 8.0,
percent: 0.9,
percent: progress,
progressColor: progressColor,
),
const SizedBox(height: 4,),

View File

@ -13,6 +13,7 @@ class StatisticsPercentage extends StatelessWidget {
@override
Widget build(BuildContext context) {
StatisticsService statisticsService = StatisticsService();
List<double> ingredients = statisticsService.getAllEatenIngredientsForTodayStatistics();
return Container(
decoration:
BoxDecoration(border: Border.all(width: 2.0, color: Colors.black)),
@ -35,12 +36,13 @@ class StatisticsPercentage extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// TODO adjust total values (200) to user inputs
LineCircularWiTextComponent(
Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"),
Colors.green.shade400, ingredients[0], 200, "Fat (g)"),
LineCircularWiTextComponent(
Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"),
Colors.green.shade400, ingredients[1], 200, "Protein (g)"),
LineCircularWiTextComponent(
Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"),
Colors.green.shade400, ingredients[2], 200, "Carbohydrate (g)"),
],
),
)

View File

@ -176,6 +176,21 @@ class StatisticsService {
return sum as int;
}
List<double> getAllEatenIngredientsForTodayStatistics(){
Box box = Hive.box(reducedStatisticsBoxName);
num fat = 0;
num protein = 0;
num carbs = 0;
for(int i = 0; i < box.keys.length;i++){
for(Food food in box.get(box.keys.elementAt(i))){
fat += food.fatg;
protein = food.proteing;
carbs = food.carbohydrateg;
}
}
return [fat as double,protein as double,carbs as double];
}
num getAllCaloriesByBoxAndTimestamp(Box box,int timestamp){
Map<String, List<Food>> valueMap = castDynamicMap(box.get(timestamp));
num sum = 0;
@ -203,6 +218,8 @@ class StatisticsService {
return sum;
}
showItems(){
print("Statistics.dart - showItems() - ITEMS");
//Hive.box(boxName).clear();