diff --git a/lib/widgets/nutrition/nutritional_plan_detail.dart b/lib/widgets/nutrition/nutritional_plan_detail.dart index 74647ea47..9ee61c009 100644 --- a/lib/widgets/nutrition/nutritional_plan_detail.dart +++ b/lib/widgets/nutrition/nutritional_plan_detail.dart @@ -46,138 +46,113 @@ class NutritionalPlanDetailWidget extends StatelessWidget { : null; return SliverList( - delegate: SliverChildListDelegate( - [ - const SizedBox(height: 10), - ..._nutritionalPlan.meals.map((meal) => MealWidget( - meal, - _nutritionalPlan.allMealItems, - )), - MealWidget( - _nutritionalPlan.pseudoMealOthers('Other logs'), - _nutritionalPlan.allMealItems, - ), - if (!_nutritionalPlan.onlyLogging) - Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - child: Text(AppLocalizations.of(context).addMeal), - onPressed: () { - Navigator.pushNamed( - context, - FormScreen.routeName, - arguments: FormScreenArguments( - AppLocalizations.of(context).addMeal, - MealForm(_nutritionalPlan.id!), - ), - ); - }, - ), - ), - Container( - padding: const EdgeInsets.all(15), - height: 220, - child: FlNutritionalPlanPieChartWidget(plannedNutritionalValues), // chart - ), + delegate: SliverChildListDelegate( + [ + const SizedBox(height: 10), + ..._nutritionalPlan.meals.map((meal) => MealWidget( + meal, + _nutritionalPlan.allMealItems, + )), + MealWidget( + _nutritionalPlan.pseudoMealOthers('Other logs'), + _nutritionalPlan.allMealItems, + ), + if (!_nutritionalPlan.onlyLogging) Padding( - padding: const EdgeInsets.symmetric(horizontal: 10), - child: MacronutrientsTable( - plannedNutritionalValues: plannedNutritionalValues, - plannedValuesPercentage: _nutritionalPlan.energyPercentage(plannedNutritionalValues), - plannedValuesGperKg: valuesGperKg, - ), - ), - const Padding(padding: EdgeInsets.all(8.0)), - Text( - AppLocalizations.of(context).logged, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleLarge, - ), - Container( - padding: const EdgeInsets.only(top: 15, left: 15, right: 15), - height: 300, - child: NutritionalDiaryChartWidgetFl(nutritionalPlan: _nutritionalPlan), // chart - ), - Padding( - padding: const EdgeInsets.only(bottom: 40, left: 25, right: 25), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Indicator( - color: LIST_OF_COLORS3[0], - text: AppLocalizations.of(context).deficit, - isSquare: true, - marginRight: 0, - ), - Indicator( - color: COLOR_SURPLUS, - text: AppLocalizations.of(context).surplus, - isSquare: true, - marginRight: 0, - ), - Indicator( - color: LIST_OF_COLORS3[1], - text: AppLocalizations.of(context).today, - isSquare: true, - marginRight: 0, - ), - Indicator( - color: LIST_OF_COLORS3[2], - text: AppLocalizations.of(context).weekAverage, - isSquare: true, - marginRight: 0, - ), - ], - ), - ), - if (_nutritionalPlan.logEntriesValues.isNotEmpty) - Column( - children: [ - Text( - AppLocalizations.of(context).nutritionalDiary, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleSmall, - ), - Container( - padding: const EdgeInsets.all(15), - height: 220, - child: FlNutritionalDiaryChartWidget(nutritionalPlan: _nutritionalPlan), // chart - ), - SizedBox( - height: 200, - child: ListView( - scrollDirection: Axis.horizontal, - children: [ - Padding( - padding: const EdgeInsets.all(8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - TextButton(onPressed: () {}, child: const Text('')), - Text( - '${AppLocalizations.of(context).energyShort} (${AppLocalizations.of(context).kcal})'), - Text( - '${AppLocalizations.of(context).proteinShort} (${AppLocalizations.of(context).g})'), - Text( - '${AppLocalizations.of(context).carbohydratesShort} (${AppLocalizations.of(context).g})'), - Text( - '${AppLocalizations.of(context).fatShort} (${AppLocalizations.of(context).g})'), - ], - ), - ), - ..._nutritionalPlan.logEntriesValues.entries - .map((entry) => - NutritionDiaryEntry(entry.key, entry.value, _nutritionalPlan)) - .toList() - .reversed, - ], + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + child: Text(AppLocalizations.of(context).addMeal), + onPressed: () { + Navigator.pushNamed( + context, + FormScreen.routeName, + arguments: FormScreenArguments( + AppLocalizations.of(context).addMeal, + MealForm(_nutritionalPlan.id!), ), - ) - ], + ); + }, ), - ], - ), - ); + ), + Container( + padding: const EdgeInsets.all(15), + height: 220, + child: FlNutritionalPlanPieChartWidget(plannedNutritionalValues), // chart + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: MacronutrientsTable( + plannedNutritionalValues: plannedNutritionalValues, + plannedValuesPercentage: _nutritionalPlan.energyPercentage(plannedNutritionalValues), + plannedValuesGperKg: valuesGperKg, + ), + ), + const Padding(padding: EdgeInsets.all(8.0)), + Text( + AppLocalizations.of(context).logged, + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleLarge, + ), + Container( + padding: const EdgeInsets.only(top: 15, left: 15, right: 15), + height: 300, + child: NutritionalDiaryChartWidgetFl(nutritionalPlan: _nutritionalPlan), // chart + ), + Padding( + padding: const EdgeInsets.only(bottom: 40, left: 25, right: 25), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Indicator( + color: LIST_OF_COLORS3[0], + text: AppLocalizations.of(context).deficit, + isSquare: true, + marginRight: 0, + ), + Indicator( + color: COLOR_SURPLUS, + text: AppLocalizations.of(context).surplus, + isSquare: true, + marginRight: 0, + ), + Indicator( + color: LIST_OF_COLORS3[1], + text: AppLocalizations.of(context).today, + isSquare: true, + marginRight: 0, + ), + Indicator( + color: LIST_OF_COLORS3[2], + text: AppLocalizations.of(context).weekAverage, + isSquare: true, + marginRight: 0, + ), + ], + ), + ), + if (_nutritionalPlan.logEntriesValues.isNotEmpty) + Column( + children: [ + Text( + AppLocalizations.of(context).nutritionalDiary, + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleSmall, + ), + SizedBox( + height: 200, + child: SingleChildScrollView( + child: Table( + children: [ + nutrionalDiaryHeader(context, _nutritionalPlan), + ..._nutritionalPlan.logEntriesValues.entries.map((entry) => + nutritionDiaryEntry(context, entry.key, entry.value, _nutritionalPlan)) + ], + ), + )), + ], + ), + ], + )); } } @@ -334,38 +309,38 @@ class MacronutrientsTable extends StatelessWidget { } } -class NutritionDiaryEntry extends StatelessWidget { - final DateTime date; - final NutritionalValues values; - final NutritionalPlan plan; - - const NutritionDiaryEntry( - this.date, - this.values, - this.plan, +TableRow nutrionalDiaryHeader(BuildContext context, final NutritionalPlan plan) { + return TableRow( + children: [ + TextButton(onPressed: () {}, child: const Text('')), + Text('${AppLocalizations.of(context).energyShort} (${AppLocalizations.of(context).kcal})'), + if (plan.goalEnergy != null) Text(AppLocalizations.of(context).difference), + Text('${AppLocalizations.of(context).protein} (${AppLocalizations.of(context).g})'), + Text( + '${AppLocalizations.of(context).carbohydratesShort} (${AppLocalizations.of(context).g})'), + Text('${AppLocalizations.of(context).fatShort} (${AppLocalizations.of(context).g})'), + ], + ); +} + +TableRow nutritionDiaryEntry(final BuildContext context, final DateTime date, + final NutritionalValues values, final NutritionalPlan plan) { + return TableRow( + children: [ + GestureDetector( + onTap: () => Navigator.of(context).pushNamed( + NutritionalDiaryScreen.routeName, + arguments: NutritionalDiaryArguments(plan, date), + ), + child: Text( + style: TextStyle(color: LIST_OF_COLORS3.first), + DateFormat.Md(Localizations.localeOf(context).languageCode).format(date), + )), + Text(values.energy.toStringAsFixed(0)), + if (plan.goalEnergy != null) Text((values.energy - plan.goalEnergy!).toStringAsFixed(0)), + Text(values.protein.toStringAsFixed(0)), + Text(values.carbohydrates.toStringAsFixed(0)), + Text(values.fat.toStringAsFixed(0)), + ], ); - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - TextButton( - onPressed: () => Navigator.of(context).pushNamed( - NutritionalDiaryScreen.routeName, - arguments: NutritionalDiaryArguments(plan, date), - ), - child: Text( - DateFormat.yMd(Localizations.localeOf(context).languageCode).format(date), - )), - Text(values.energy.toStringAsFixed(0)), - Text(values.protein.toStringAsFixed(0)), - Text(values.carbohydrates.toStringAsFixed(0)), - Text(values.fat.toStringAsFixed(0)), - ], - ), - ); - } }