calorimeter/lib/sum_widget.dart

31 lines
790 B
Dart
Raw Normal View History

2024-06-09 12:42:17 +00:00
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});
2024-06-09 12:42:17 +00:00
@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'),
2024-06-09 12:42:17 +00:00
null,
);
},
);
}
}