Skip to content

Refactor/nutrition meals components#1224

Merged
rolandgeider merged 5 commits into
wger-project:masterfrom
pankaj-basnet:refactor/nutrition-meals-components
Jun 18, 2026
Merged

Refactor/nutrition meals components#1224
rolandgeider merged 5 commits into
wger-project:masterfrom
pankaj-basnet:refactor/nutrition-meals-components

Conversation

@pankaj-basnet

Copy link
Copy Markdown
Contributor

Summary

This PR refactors widgets/nutrition/meal.dart
(MealWidget), extract large inline sections into named sub-components.


Issue/Problem

_MealWidgetState.build() was ~160 lines long, with deeply nested if
blocks for the editing toolbar, divider, ingredient list, total row, and diary section.
Reading and modifying this method required tracking all four ViewMode conditions
simultaneously.


Changes

providers/nutrition_notifier.dart
  └── NutritionState.recentMealItemsInPlan()  [NEW METHOD]

widgets/nutrition/meal.dart
  ├── enum viewMode → ViewMode            [NAMING FIX]
  ├── MealWidget constructor              
  │    removed: List<MealItem> _recentMealItems
  ├── MealIngredientsSection              [NEW ConsumerWidget]
  │    extracted: dividers, DiaryheaderTile, ingredient list, total row
  └── MealEditingToolbar                  [NEW ConsumerWidget]
       self-serves recentMealItems via ref.watch(nutritionProvider)

widgets/nutrition/nutritional_plan_detail.dart
  └── MealWidget call-sites               [CALL-SITE CLEANED]
       removed: _nutritionalPlan.dedupMealItems argument (×2)

Files Changed

# File Change Type
1 lib/providers/nutrition_notifier.dart Added recentMealItemsInPlan() to NutritionState
2 lib/widgets/nutrition/meal.dart Refactor — extracted 2 sub-widgets
3 lib/widgets/nutrition/nutritional_plan_detail.dart Updated 2 MealWidget call-sites

Testing

  • refactored meal_test.dart

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Set a 100-character limit to avoid white space diffs (run dart format .)

- Extract date display logic in nutritional plan details
- Migrate hardcoded strings to localization files
- Update MealWidget constructor call
- Add interaction steps to reveal ingredients section before testing the add button
Comment thread lib/widgets/nutrition/charts.dart Outdated
Comment thread lib/widgets/nutrition/meal.dart
@rolandgeider

Copy link
Copy Markdown
Member

Now that we have merged the offiline mode, we can finally start working on simpler stuff like this! :)

- revert translation changes in charts and cleanup meal logs
- fix for the Meal test
@pankaj-basnet

Copy link
Copy Markdown
Contributor Author

YEAH! refactoring this meal.dart file was in my todo list for few weeks now

@rolandgeider rolandgeider merged commit 9bc0b15 into wger-project:master Jun 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants