mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Merge pull request #603 from wger-project/show-kcal-consumed-vs-planned-on-meal-tiles
show kcal consumed vs planned, on meal tiles
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:wger/models/nutrition/meal.dart';
|
||||
import 'package:wger/models/nutrition/nutritional_values.dart';
|
||||
import 'package:wger/widgets/core/core.dart';
|
||||
|
||||
@@ -49,3 +50,18 @@ String getShortNutritionValues(NutritionalValues values, BuildContext context) {
|
||||
final f = '${loc.fatShort} ${loc.gValue(values.fat.toStringAsFixed(0))}';
|
||||
return '$e / $p / $c / $f';
|
||||
}
|
||||
|
||||
String getKcalConsumed(Meal meal, BuildContext context) {
|
||||
final consumed =
|
||||
meal.diaryEntriesToday.map((e) => e.nutritionalValues.energy).fold(0.0, (a, b) => a + b);
|
||||
return AppLocalizations.of(context).kcalValue(consumed.toStringAsFixed(0));
|
||||
}
|
||||
|
||||
String getKcalConsumedVsPlanned(Meal meal, BuildContext context) {
|
||||
final planned = meal.plannedNutritionalValues.energy;
|
||||
final consumed =
|
||||
meal.diaryEntriesToday.map((e) => e.nutritionalValues.energy).fold(0.0, (a, b) => a + b);
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
return '${consumed.toStringAsFixed(0)} / ${planned.toStringAsFixed(0)} ${loc.kcal}';
|
||||
}
|
||||
|
||||
@@ -318,14 +318,25 @@ class MealHeader extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
((_meal.time != null) ? '${_meal.time!.format(context)} ' : '') + _meal.name,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
_meal.name,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
if (_meal.time != null)
|
||||
Text(
|
||||
_meal.time!.format(context),
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
if (_meal.time != null) const SizedBox(width: 12),
|
||||
Text(
|
||||
_meal.isRealMeal
|
||||
? getKcalConsumedVsPlanned(_meal, context)
|
||||
: getKcalConsumed(_meal, context),
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_meal.isRealMeal)
|
||||
Text(
|
||||
getShortNutritionValues(_meal.plannedNutritionalValues, context),
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
],
|
||||
)),
|
||||
]),
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 68 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
Reference in New Issue
Block a user