mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-21 21:42:17 +01:00
Twelfth batch of the 250-line sweep (over-cap count 5 -> 4). log_meal_screen.dart 431 -> 250 Widget/behaviour extraction only, no route changes: the four app-bar buttons push exactly the MaterialPageRoutes they did before. log_meal_sync_mixin.dart background sync + app lifecycle observation log_meal_nav_mixin.dart the four app-bar destinations log_meal_actions.dart the app-bar IconButton list log_meal_progress.dart buildTodayProgress + parseMacroField (both pure) The sync and nav halves are mixins rather than helper classes because the behaviour is inseparable from the State it drives -- it observes the widget lifecycle, calls setState, and reads `mounted`. The screen's fields stay declared on the State; `syncHttpClient` is an abstract getter because `widget` is typed `T` inside a mixin, so `widget.httpClient` does not resolve there. Names crossing the new file boundaries became public with doc comments, as `public_member_api_docs` requires. The macro-filling block moved onto `MacroControllers.fillFrom`, next to the existing `clear()`, which is where it belonged anyway. Verified: flutter test 555 (unchanged), flutter analyze clean, pre-commit clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RA9ynjqXPnexRQnR5oAuCC
37 lines
1.4 KiB
Dart
37 lines
1.4 KiB
Dart
import 'package:diet_guard_app/models/food_entry.dart';
|
|
import 'package:diet_guard_app/models/local_time.dart';
|
|
import 'package:diet_guard_app/services/app_settings_service.dart';
|
|
import 'package:diet_guard_app/services/budget_history_service.dart';
|
|
import 'package:diet_guard_app/services/day_status_service.dart';
|
|
import 'package:diet_guard_app/services/log_storage_service.dart';
|
|
import 'package:diet_guard_app/widgets/today_progress_card.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Reads a macro field as a number, treating blank or unparsable as zero.
|
|
double parseMacroField(TextEditingController controller) =>
|
|
double.tryParse(controller.text.trim()) ?? 0;
|
|
|
|
/// Summarises today from the log just written.
|
|
///
|
|
/// Takes the already-read [log] rather than re-reading, so the card can
|
|
/// never disagree with the write that produced it.
|
|
TodayProgress buildTodayProgress(DayLog log, String desc) {
|
|
final budget = AppSettingsService.dailyKcalGoal;
|
|
final today = localDateKey(DateTime.now());
|
|
final entries = (log[today] ?? const <FoodEntry>[])
|
|
.where((entry) => !entry.deleted)
|
|
.toList();
|
|
final macros = sumMacros(entries);
|
|
return TodayProgress(
|
|
justLogged: desc,
|
|
consumedKcal: sumKcal(entries),
|
|
budgetKcal: budget,
|
|
proteinG: macros.proteinG,
|
|
carbsG: macros.carbsG,
|
|
fatG: macros.fatG,
|
|
adherenceStreak: adherenceStreak(
|
|
statusMap(log, schedule: BudgetHistoryService.schedule),
|
|
),
|
|
);
|
|
}
|