mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-10 18:07:20 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
105 lines
3.0 KiB
Dart
105 lines
3.0 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/widgets/body/body_section.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// 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 normal = report.category == 'normal';
|
|
return BodySection(
|
|
title: 'BMI',
|
|
children: [
|
|
BodyStatRow(
|
|
'BMI',
|
|
oneDecimal(report.bmi),
|
|
color: normal ? null : Theme.of(context).colorScheme.error,
|
|
),
|
|
BodyStatRow('Category', report.category),
|
|
BodyStatRow('BMI Prime', halfUp(report.prime, 2).toStringAsFixed(2)),
|
|
BodyStatRow('Trefethen (new BMI)', oneDecimal(report.trefethen)),
|
|
BodyStatRow(
|
|
'Healthy weight for your height (BMI 18.5-24.9)',
|
|
'${oneDecimal(low)}-${oneDecimal(high)} kg',
|
|
),
|
|
const BodyNote(bmiPrimeNote),
|
|
const BodyNote(trefethenNote),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Every ideal-weight formula; `n/a` 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 undefined = formulas.any((f) => f.value == null);
|
|
final summary = idealSummary(formulas);
|
|
return BodySection(
|
|
title: 'Ideal weight',
|
|
children: [
|
|
for (final formula in formulas)
|
|
BodyStatRow(formula.name, formatKg(formula.value)),
|
|
if (summary != null) ...[
|
|
const Divider(),
|
|
BodyStatRow('Average of all', formatKg(summary.$1)),
|
|
BodyStatRow(
|
|
'Ideal range',
|
|
'${oneDecimal(summary.$2)}-${oneDecimal(summary.$3)} kg',
|
|
),
|
|
],
|
|
if (undefined)
|
|
const BodyNote(
|
|
'Devine, Robinson and Miller are undefined below 152.4 cm.',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 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(
|
|
title: 'Resting metabolism (BMR)',
|
|
children: [
|
|
for (final formula in bmrFormulas(bio, bodyFatPct))
|
|
BodyStatRow(
|
|
formula.name,
|
|
formula.value == null
|
|
? 'n/a -- log a body-fat %'
|
|
: '${whole(formula.value!)} kcal',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|