mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-22 04:12:25 +01:00
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation infos failed flutter analyze --fatal-infos, and four Dart pins were behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2, github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages now sit on material_ui, so the app has to as well or their widgets lose MaterialLocalizations. Imports swap one-for-one and dart fix re-sorted the directives; no behaviour change. analyze is clean and all six test shards pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
147 lines
4.4 KiB
Dart
147 lines
4.4 KiB
Dart
/// BMI, ideal-weight and BMR cards -- read-only views of `body_calc.dart`.
|
|
library;
|
|
|
|
import 'package:diet_guard_app/services/body_calc.dart';
|
|
import 'package:diet_guard_app/ui/cues.dart';
|
|
import 'package:diet_guard_app/ui/macro_kind.dart';
|
|
import 'package:diet_guard_app/ui/theme.dart';
|
|
import 'package:diet_guard_app/widgets/body/body_section.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
|
|
/// The BMI band as glyph + colour (never colour alone): a green check inside
|
|
/// the healthy range, an amber or red arrow towards the side it is off by.
|
|
(IconData, CueKind) bmiBandCue(String category) {
|
|
if (category == 'normal') return (Icons.check_circle, CueKind.ok);
|
|
if (category.contains('thinness')) {
|
|
return (Icons.trending_down, CueKind.warn);
|
|
}
|
|
if (category.startsWith('overweight')) {
|
|
return (Icons.trending_up, CueKind.warn);
|
|
}
|
|
if (category.startsWith('obese')) return (Icons.trending_up, CueKind.error);
|
|
return (Icons.help_outline, CueKind.info);
|
|
}
|
|
|
|
/// BMI, BMI Prime, Trefethen's BMI and the WHO category.
|
|
class BmiCard extends StatelessWidget {
|
|
/// Creates the card for [bio].
|
|
const BmiCard({required this.bio, super.key});
|
|
|
|
/// The person.
|
|
final Biometrics bio;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final report = bmiReport(bio);
|
|
final (low, high) = healthyRange(bio);
|
|
final (icon, kind) = bmiBandCue(report.category);
|
|
final tint = kind.tint(context);
|
|
return BodySection(
|
|
semanticLabel: 'BMI',
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(icon, color: tint, semanticLabel: report.category),
|
|
const SizedBox(width: AppSpacing.sm),
|
|
Text(
|
|
oneDecimal(report.bmi),
|
|
style: Theme.of(
|
|
context,
|
|
).textTheme.headlineMedium?.copyWith(color: tint),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: AppSpacing.sm),
|
|
BodyStatRow.named(
|
|
'BMI Prime',
|
|
halfUp(report.prime, 2).toStringAsFixed(2),
|
|
),
|
|
BodyStatRow.named('Trefethen', oneDecimal(report.trefethen)),
|
|
BodyStatRow.icon(
|
|
Icons.favorite,
|
|
'Healthy weight for your height (BMI 18.5-24.9)',
|
|
'${oneDecimal(low)}-${oneDecimal(high)} kg',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Every ideal-weight formula; a dash where one is undefined.
|
|
class IdealWeightCard extends StatelessWidget {
|
|
/// Creates the card for [bio].
|
|
const IdealWeightCard({required this.bio, super.key});
|
|
|
|
/// The person.
|
|
final Biometrics bio;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final formulas = idealWeights(bio);
|
|
final summary = idealSummary(formulas);
|
|
return BodySection(
|
|
semanticLabel: 'Ideal weight',
|
|
children: [
|
|
for (final formula in formulas)
|
|
BodyStatRow.named(formula.name, formatKg(formula.value)),
|
|
if (summary != null) ...[
|
|
const Divider(),
|
|
BodyStatRow.icon(
|
|
Icons.functions,
|
|
'Average of all',
|
|
formatKg(summary.$1),
|
|
),
|
|
BodyStatRow.icon(
|
|
Icons.swap_horiz,
|
|
'Ideal range',
|
|
'${oneDecimal(summary.$2)}-${oneDecimal(summary.$3)} kg',
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Resting metabolic rate by every formula; lean-mass ones need body fat.
|
|
class BmrCard extends StatelessWidget {
|
|
/// Creates the card for [bio].
|
|
const BmrCard({required this.bio, this.bodyFatPct, super.key});
|
|
|
|
/// The person.
|
|
final Biometrics bio;
|
|
|
|
/// The newest body fat %, or null.
|
|
final double? bodyFatPct;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BodySection(
|
|
semanticLabel: 'Resting metabolism (BMR)',
|
|
children: [
|
|
for (final formula in bmrFormulas(bio, bodyFatPct))
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs / 2),
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text(formula.name)),
|
|
if (formula.value == null)
|
|
Icon(
|
|
Icons.percent,
|
|
size: 18,
|
|
color: CueKind.warn.tint(context),
|
|
semanticLabel: 'n/a -- log a body-fat %',
|
|
)
|
|
else
|
|
MacroFigure(
|
|
kind: MacroKind.kcal,
|
|
value: whole(formula.value!),
|
|
size: 16,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|