2024-06-09 12:42:17 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-09-06 17:00:25 +00:00
|
|
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
|
|
|
import 'package:calorimeter/utils/settings_bloc.dart';
|
2024-06-09 12:42:17 +00:00
|
|
|
|
2024-09-07 23:57:40 +00:00
|
|
|
class SumWidget extends StatelessWidget {
|
2024-09-09 20:41:48 +00:00
|
|
|
final List<FoodEntryState> foodEntries;
|
2024-06-11 17:05:42 +00:00
|
|
|
const SumWidget({required this.foodEntries, super.key});
|
2024-06-10 01:06:56 +00:00
|
|
|
|
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-09-07 23:57:40 +00:00
|
|
|
for (var entry in foodEntries) {
|
2024-09-24 15:23:01 +00:00
|
|
|
sum += entry.kcalPer100 / 100 * entry.mass;
|
2024-06-09 12:42:17 +00:00
|
|
|
}
|
2024-09-07 23:57:40 +00:00
|
|
|
var diff = state.kcalLimit - sum;
|
|
|
|
var diffLimit = state.kcalLimit ~/ 4;
|
|
|
|
|
|
|
|
var textColor = Theme.of(context).colorScheme.onSecondary;
|
|
|
|
var newTextColor = textColor;
|
|
|
|
var brightness = Theme.of(context).brightness;
|
|
|
|
|
|
|
|
switch (brightness) {
|
|
|
|
case Brightness.dark:
|
|
|
|
if (diff < 0) {
|
|
|
|
newTextColor = Colors.red[900]!;
|
|
|
|
} else if (diff < diffLimit) {
|
|
|
|
newTextColor = Colors.orange[900]!;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Brightness.light:
|
|
|
|
if (diff < 0) {
|
|
|
|
newTextColor = Colors.redAccent;
|
|
|
|
} else if (diff < diffLimit) {
|
|
|
|
newTextColor = Colors.orangeAccent;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-06-09 12:42:17 +00:00
|
|
|
|
2024-09-07 23:57:40 +00:00
|
|
|
return Align(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
2024-09-05 14:36:35 +00:00
|
|
|
'kcal heute: ${sum.ceil().toString()}/${state.kcalLimit.ceil()}',
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
2024-09-07 23:57:40 +00:00
|
|
|
.bodyLarge!
|
|
|
|
.copyWith(color: newTextColor),
|
2024-09-05 14:36:35 +00:00
|
|
|
),
|
2024-06-09 12:42:17 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|