calorimeter/lib/sum_widget.dart

31 lines
790 B
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:kalodings/food_entry_bloc.dart';
import 'package:kalodings/row_with_spacers_widget.dart';
class SumWidget extends StatelessWidget {
final double limit;
const SumWidget({required this.limit, super.key});
@override
Widget build(BuildContext context) {
return BlocBuilder<FoodEntryBloc, FoodEntryState>(
builder: (context, state) {
var sum = 0.0;
for (var entry in state.foodEntries) {
sum += entry.kcalPerMass / 100 * entry.mass;
}
return RowWidgetWithSpacers(
null,
null,
const Text("kcal heute:"),
Text('${sum.toString()}/$limit'),
null,
);
},
);
}
}