41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:calodiary/food_entry/food_entry_bloc.dart';
|
|
import 'package:calodiary/utils/settings_bloc.dart';
|
|
import 'package:calodiary/row_with_spacers_widget.dart';
|
|
|
|
class SumWidget extends StatefulWidget {
|
|
final List<FoodEntry> foodEntries;
|
|
const SumWidget({required this.foodEntries, super.key});
|
|
|
|
@override
|
|
State<SumWidget> createState() => _SumWidgetState();
|
|
}
|
|
|
|
class _SumWidgetState extends State<SumWidget> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<SettingsDataBloc, SettingsState>(
|
|
builder: (context, state) {
|
|
var sum = 0.0;
|
|
for (var entry in widget.foodEntries) {
|
|
sum += entry.kcalPerMass / 100 * entry.mass;
|
|
}
|
|
|
|
return RowWidget(
|
|
Text(
|
|
'kcal heute: ${sum.ceil().toString()}/${state.kcalLimit.ceil()}',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyMedium!
|
|
.copyWith(color: Theme.of(context).colorScheme.onPrimary),
|
|
),
|
|
null,
|
|
null,
|
|
null,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|