feat: add ingredient progress bars to page
parent
77023ad118
commit
b201a6758b
|
@ -5,28 +5,28 @@ import 'package:percent_indicator/linear_percent_indicator.dart';
|
||||||
|
|
||||||
class LineCircularWiTextComponent extends StatelessWidget {
|
class LineCircularWiTextComponent extends StatelessWidget {
|
||||||
final Color progressColor;
|
final Color progressColor;
|
||||||
final double percent;
|
final double value;
|
||||||
final int left;
|
|
||||||
final int total;
|
final int total;
|
||||||
final String textName;
|
final String textName;
|
||||||
|
|
||||||
const LineCircularWiTextComponent(
|
const LineCircularWiTextComponent(
|
||||||
this.progressColor, this.percent, this.left, this.total, this.textName,
|
this.progressColor, this.value, this.total, this.textName,
|
||||||
{super.key});
|
{super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
double progress = double.parse((value/total).toStringAsFixed(1));
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
|
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
StaticsTextComponent(left.toString(), true),
|
StaticsTextComponent(double.parse(value.toString()).toStringAsFixed(2), true),
|
||||||
const SizedBox(height: 4,),
|
const SizedBox(height: 4,),
|
||||||
LinearPercentIndicator(
|
LinearPercentIndicator(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
lineHeight: 8.0,
|
lineHeight: 8.0,
|
||||||
percent: 0.9,
|
percent: progress,
|
||||||
progressColor: progressColor,
|
progressColor: progressColor,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4,),
|
const SizedBox(height: 4,),
|
||||||
|
|
|
@ -13,6 +13,7 @@ class StatisticsPercentage extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
StatisticsService statisticsService = StatisticsService();
|
StatisticsService statisticsService = StatisticsService();
|
||||||
|
List<double> ingredients = statisticsService.getAllEatenIngredientsForTodayStatistics();
|
||||||
return Container(
|
return Container(
|
||||||
decoration:
|
decoration:
|
||||||
BoxDecoration(border: Border.all(width: 2.0, color: Colors.black)),
|
BoxDecoration(border: Border.all(width: 2.0, color: Colors.black)),
|
||||||
|
@ -35,12 +36,13 @@ class StatisticsPercentage extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
|
// TODO adjust total values (200) to user inputs
|
||||||
LineCircularWiTextComponent(
|
LineCircularWiTextComponent(
|
||||||
Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"),
|
Colors.green.shade400, ingredients[0], 200, "Fat (g)"),
|
||||||
LineCircularWiTextComponent(
|
LineCircularWiTextComponent(
|
||||||
Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"),
|
Colors.green.shade400, ingredients[1], 200, "Protein (g)"),
|
||||||
LineCircularWiTextComponent(
|
LineCircularWiTextComponent(
|
||||||
Colors.green.shade400, 1.0, 1000, 2000, "Konsumiert"),
|
Colors.green.shade400, ingredients[2], 200, "Carbohydrate (g)"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -176,6 +176,21 @@ class StatisticsService {
|
||||||
return sum as int;
|
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){
|
num getAllCaloriesByBoxAndTimestamp(Box box,int timestamp){
|
||||||
Map<String, List<Food>> valueMap = castDynamicMap(box.get(timestamp));
|
Map<String, List<Food>> valueMap = castDynamicMap(box.get(timestamp));
|
||||||
num sum = 0;
|
num sum = 0;
|
||||||
|
@ -203,6 +218,8 @@ class StatisticsService {
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
showItems(){
|
showItems(){
|
||||||
print("Statistics.dart - showItems() - ITEMS");
|
print("Statistics.dart - showItems() - ITEMS");
|
||||||
//Hive.box(boxName).clear();
|
//Hive.box(boxName).clear();
|
||||||
|
|
Loading…
Reference in New Issue