Skip to content

feat(add-meal): suggest a meal type from the current time (#580) - #590

Open
ibrahim-iqbal wants to merge 1 commit into
simonoppowa:mainfrom
ibrahim-iqbal:feature/580-meal-type-from-time
Open

feat(add-meal): suggest a meal type from the current time (#580)#590
ibrahim-iqbal wants to merge 1 commit into
simonoppowa:mainfrom
ibrahim-iqbal:feature/580-meal-type-from-time

Conversation

@ibrahim-iqbal

Copy link
Copy Markdown

Fixes #580.

Summary

Preselect a meal type in the global add-item bottom sheet based on the device's local time. Every tile stays immediately tappable; the suggestion renders as a small Suggested chip on the matching tile so nothing changes about the tap flow.

Approach

  • New MealTypeSuggester.suggestFromTime(DateTime) in lib/core/utils/ centralizes the time-of-day ranges so they can be tweaked in one place:
    • Breakfast: 04:00 – 10:59
    • Lunch: 11:00 – 14:59
    • Snack: 15:00 – 16:59
    • Dinner: 17:00 – 21:59
    • Snack: 22:00 – 03:59 (late night / pre-dawn)
  • AddItemBottomSheet accepts a nullable suggestedType. The global + action in main_screen.dart passes MealTypeSuggester.suggestFromTime(DateTime.now()). Flows launched from a specific meal section keep passing nothing and see no highlight, per the acceptance criteria.
  • The Suggested chip uses colorScheme.secondaryContainer / onSecondaryContainer so it inherits both light and dark themes cleanly.

Acceptance criteria mapping

  • Define time ranges in one testable helper — MealTypeSuggester
  • Use device local time to determine the initial suggestion — MealTypeSuggester.suggestFromTime(DateTime.now()) in main_screen.dart
  • Visually preselect the suggested meal type when opened from global +Suggested chip on the matching tile
  • Let the user choose a different meal type before continuing — every tile stays tappable (unchanged onTap handlers)
  • Do not change flows launched from a specific meal section — those callers keep passing nothing, so suggestedType stays null and no chip renders
  • Handle boundary times deterministically — inclusive-start / exclusive-end ranges; boundary hours (04, 11, 15, 17, 22, 00, 03:59) covered in tests
  • Add unit / widget tests covering each range, boundaries, and explicit meal-section behavior — 6 unit tests + 2 widget tests
  • Add or preserve stable Semantics(identifier: ...) values — chip has add-item-suggested-chip; the existing tile identifiers are untouched

Tests

  • test/core/utils/meal_type_suggester_test.dart — 6 unit tests covering every range and each boundary hour
  • test/core/presentation/widgets/add_item_bottom_sheet_test.dart — 2 new widget tests: chip renders on the matching tile, no chip renders when suggestedType is null

All 11 tests in the two files pass; flutter analyze clean on the touched files.

Localization

Adds suggestedLabel: "Suggested" to lib/l10n/intl_en.arb. Other locales fall back to English until they're translated.

…a#580)

Preselect Breakfast/Lunch/Dinner/Snack in the global add-item bottom
sheet based on the device's local time. Every tile stays immediately
tappable; the suggestion is a visual default rendered as a compact
'Suggested' chip on the matching tile.

- MealTypeSuggester.suggestFromTime() centralizes the time -> meal-type
  ranges so they can be tweaked in one place (04-11 breakfast,
  11-15 lunch, 15-17 snack, 17-22 dinner, 22-04 snack).
- AddItemBottomSheet accepts a nullable suggestedType. main_screen (the
  global + FAB) passes MealTypeSuggester.suggestFromTime(DateTime.now()).
  Flows launched from a specific meal section keep passing null and see
  no highlight, per the issue's acceptance criteria.
- Unit tests cover every range and each boundary hour (04, 11, 15, 17,
  22, 00, 03:59) deterministically. Widget tests cover the preselect
  visual and the null-behavior path.
- Adds 'suggestedLabel' to intl_en.arb; other locales inherit the
  English fallback until they're translated.
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.

Suggest a meal type from the current time

1 participant