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';
|
2024-06-11 17:05:42 +00:00
|
|
|
import 'package:kalodings/settings_bloc.dart';
|
2024-06-09 12:42:17 +00:00
|
|
|
import 'package:kalodings/row_with_spacers_widget.dart';
|
|
|
|
|
2024-06-11 17:05:42 +00:00
|
|
|
class SumWidget extends StatefulWidget {
|
|
|
|
final List<FoodEntry> foodEntries;
|
|
|
|
const SumWidget({required this.foodEntries, super.key});
|
2024-06-10 01:06:56 +00:00
|
|
|
|
2024-06-11 17:05:42 +00:00
|
|
|
@override
|
|
|
|
State<SumWidget> createState() => _SumWidgetState();
|
|
|
|
}
|
2024-06-09 12:42:17 +00:00
|
|
|
|
2024-06-11 17:05:42 +00:00
|
|
|
class _SumWidgetState extends State<SumWidget> {
|
2024-06-09 12:42:17 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-11 17:05:42 +00:00
|
|
|
return BlocBuilder<SettingsDataBloc, SettingsState>(
|
2024-06-09 12:42:17 +00:00
|
|
|
builder: (context, state) {
|
|
|
|
var sum = 0.0;
|
2024-06-11 17:05:42 +00:00
|
|
|
for (var entry in widget.foodEntries) {
|
2024-06-09 12:42:17 +00:00
|
|
|
sum += entry.kcalPerMass / 100 * entry.mass;
|
|
|
|
}
|
|
|
|
|
2024-06-10 15:35:21 +00:00
|
|
|
return RowWidget(
|
2024-06-09 12:42:17 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
const Text("kcal heute:"),
|
2024-06-11 17:05:42 +00:00
|
|
|
Text('${sum.toString()}/${state.kcalLimit}'),
|
2024-06-09 12:42:17 +00:00
|
|
|
null,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|