Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Blood pressure, notes and left and right in measurements, abdomen and a clearer body fat calculator
InlitX53b40d0c58e4
diff --git a/lib/app/desktop.dart b/lib/app/desktop.dartindex 1781515..861be6e 100644--- a/lib/app/desktop.dart+++ b/lib/app/desktop.dart@@ -14,7 +14,10 @@ class DesktopScope extends InheritedWidget {static const readingWidth = 760.0;static const flowWidth = 1600.0;- static bool wideFor(double width) => kIsWeb && width >= minWidth;+ @visibleForTesting+ static bool forceWide = false;++ static bool wideFor(double width) => (kIsWeb || forceWide) && width >= minWidth;static bool of(BuildContext context) =>context.dependOnInheritedWidgetOfExactType<DesktopScope>()?.wide ?? false;diff --git a/lib/models/measure.dart b/lib/models/measure.dartindex 7cbf78e..b99a574 100644--- a/lib/models/measure.dart+++ b/lib/models/measure.dart@@ -5,25 +5,50 @@ const List<String> kMeasureKeys = ['arm','forearm','waist',+ 'abdomen','hips','thigh','calf','bodyfat',+ 'bp',];+const Set<String> kSidedMeasureKeys = {'arm', 'forearm', 'thigh', 'calf'};+class BodyMeasure {- const BodyMeasure(this.date, this.key, this.value);+ const BodyMeasure(this.date, this.key, this.value, {this.note = '', this.left, this.right, this.low, this.pulse});final DateTime date;final String key;final double value;+ final String note;+ final double? left;+ final double? right;+ final double? low;+ final int? pulse;++ bool get sided => left != null && right != null;- Map<String, dynamic> toJson() => {'d': date.toIso8601String(), 'k': key, 'v': value};+ Map<String, dynamic> toJson() => {+ 'd': date.toIso8601String(),+ 'k': key,+ 'v': value,+ if (note.isNotEmpty) 'n': note,+ if (left != null) 'l': left,+ if (right != null) 'r': right,+ if (low != null) 'lo': low,+ if (pulse != null) 'p': pulse,+ };factory BodyMeasure.fromJson(Map<String, dynamic> j) => BodyMeasure(DateTime.tryParse((j['d'] ?? '') as String) ?? DateTime.now(),(j['k'] ?? '') as String,((j['v'] ?? 0) as num).toDouble(),+ note: (j['n'] as String?) ?? '',+ left: (j['l'] as num?)?.toDouble(),+ right: (j['r'] as num?)?.toDouble(),+ low: (j['lo'] as num?)?.toDouble(),+ pulse: (j['p'] as num?)?.toInt(),);}diff --git a/lib/screens/measures_screen.dart b/lib/screens/measures_screen.dartindex 3262c1e..60c6139 100644--- a/lib/screens/measures_screen.dart+++ b/lib/screens/measures_screen.dart@@ -169,7 +169,7 @@ class _MeasureRow extends StatelessWidget {Row(crossAxisAlignment: CrossAxisAlignment.end,children: [- Text(fit.measureValue(measureKey, latest.value),+ Text(fit.measureHeadline(latest),style: AppTheme.d(26, weight: FontWeight.w700, color: gc.text)),const SizedBox(width: 4),Padding(@@ -231,6 +231,18 @@ class _MeasureSheet extends StatefulWidget {State<_MeasureSheet> createState() => _MeasureSheetState();}+class _Field {+ _Field(this.label, this.value, this.lo, this.hi, this.step, this.major, {this.on = true});++ final String label;+ double value;+ double lo;+ double hi;+ final double step;+ final int major;+ bool on;+}+class _MeasureSheetState extends State<_MeasureSheet> {static const _rangesCm = {'neck': (15.0, 80.0, 38.0),@@ -239,14 +251,19 @@ class _MeasureSheetState extends State<_MeasureSheet> {'arm': (10.0, 80.0, 34.0),'forearm': (10.0, 60.0, 28.0),'waist': (30.0, 200.0, 84.0),+ 'abdomen': (30.0, 200.0, 88.0),'hips': (40.0, 200.0, 98.0),'thigh': (20.0, 120.0, 56.0),'calf': (15.0, 80.0, 38.0),};+ final _note = TextEditingController();+String get _key => widget.measureKey;bool get _pct => fit.isPercent(_key);bool get _free => fit.isFreeMeasure(_key);+ bool get _bp => fit.isPressure(_key);+ bool get _sided => fit.isSidedMeasure(_key);double get _step => _free ? _freeStep : (_pct ? 0.5 : (fit.isInches ? 0.25 : 0.5));int get _major => _free ? 10 : (_pct ? 10 : (fit.isInches ? 4 : 10));@@ -262,21 +279,43 @@ class _MeasureSheetState extends State<_MeasureSheet> {return (_snap(fit.toDisplayCm(r.$1)), _snap(fit.toDisplayCm(r.$2)));}- late (double, double) _range = _around(_value);-double get _typedMax => _free ? 99999 : (_pct ? 100 : _snap(fit.toDisplayCm(400)));double _snap(double v) => (v / _step).round() * _step;- late double _value = () {- final latest = fit.latestMeasure(_key);- if (latest != null) return _snap(fit.toDisplayMeasure(_key, latest.value));+ double _start(double? raw) {+ if (raw != null && raw > 0) return _snap(fit.toDisplayMeasure(_key, raw));if (_free) return 50.0;if (_pct) return 20.0;return _snap(fit.toDisplayCm((_rangesCm[_key] ?? (10.0, 200.0, 50.0)).$3));- }();+ }++ _Field _length(String label, double value) {+ final (lo, hi) = _around(value);+ return _Field(label, value, lo, hi, _step, _major);+ }++ late final BodyMeasure? _latest = fit.latestMeasure(_key);++ late final _Field _single = _length('', _start(_latest?.value));+ late final List<_Field> _sides = [+ _length(t.measureLeft, _start(_latest?.left ?? _latest?.value)),+ _length(t.measureRight, _start(_latest?.right ?? _latest?.value)),+ ];+ late final List<_Field> _pressure = [+ _Field(t.bpHigh, _latest?.value ?? 120, 60, 250, 1, 10),+ _Field(t.bpLow, _latest?.low ?? 80, 30, 160, 1, 10),+ _Field(t.bpPulse, (_latest?.pulse ?? 70).toDouble(), 30, 220, 1, 10, on: _latest?.pulse != null),+ ];- String _show(double v) => decimalText(v.toStringAsFixed(_step < 0.25 ? 1 : (_step < 0.5 ? 2 : 1)));+ int _active = 0;++ List<_Field> get _fields => _bp ? _pressure : (_sided ? _sides : [_single]);++ _Field get _field => _fields[_active.clamp(0, _fields.length - 1)];++ String _show(double v) =>+ _bp ? '${v.round()}' : decimalText(v.toStringAsFixed(_step < 0.25 ? 1 : (_step < 0.5 ? 2 : 1)));(double, double) _around(double v) {final (lo, hi) = _baseRange;@@ -287,6 +326,12 @@ class _MeasureSheetState extends State<_MeasureSheet> {return (math.min(lo, v), math.max(hi, v));}+ @override+ void dispose() {+ _note.dispose();+ super.dispose();+ }+Future<void> _rename() async {final c = fit.customMeasure(_key);if (c == null) return;@@ -307,27 +352,149 @@ class _MeasureSheetState extends State<_MeasureSheet> {}void _save() {- if (_value <= 0) return;- fit.addMeasure(_key, _value);+ final note = _note.text;+ if (_bp) {+ final pulse = _pressure[2];+ fit.addPressure(_pressure[0].value.round(), _pressure[1].value.round(),+ pulse: pulse.on ? pulse.value.round() : null, note: note);+ } else if (_sided) {+ fit.addMeasure(_key, 0, left: _sides[0].value, right: _sides[1].value, note: note);+ } else {+ if (_single.value <= 0) return;+ fit.addMeasure(_key, _single.value, note: note);+ }Navigator.of(context).pop();}Future<void> _type() async {- final typed = await askNumber(context, title: fit.measureTitle(_key), initial: _show(_value), decimal: true);- if (typed == null || !mounted) return;- if (typed <= 0) return;- final v = math.max(_step, _snap(typed.clamp(_step, _typedMax)));+ final f = _field;+ final typed = await askNumber(context,+ title: f.label.isEmpty ? fit.measureTitle(_key) : f.label, initial: _show(f.value), decimal: !_bp);+ if (typed == null || !mounted || typed <= 0) return;+ setState(() {+ if (_bp) {+ f.value = typed.round().clamp(f.lo, f.hi).toDouble();+ } else {+ f.value = math.max(_step, _snap(typed.clamp(_step, _typedMax)));+ final (lo, hi) = _around(f.value);+ f.lo = lo;+ f.hi = hi;+ }+ f.on = true;+ });+ }++ void _pick(int i) {+ HapticFeedback.selectionClick();+ setState(() {+ _active = i;+ _fields[i].on = true;+ });+ }++ void _setSided(bool on) {+ if (on == _sided) return;setState(() {- _value = v;- _range = _around(v);+ fit.toggleSidedMeasure(_key);+ _active = 0;});}+ Widget _bigValue(GymColors gc) => Center(+ child: Ltr(+ child: Row(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.baseline,+ textBaseline: TextBaseline.alphabetic,+ children: [+ RollingText(_show(_single.value),+ style: AppTheme.f(54, weight: FontWeight.w800, color: gc.text, height: 1.1)),+ const SizedBox(width: 6),+ Text(fit.measureUnit(_key), style: AppTheme.f(18, weight: FontWeight.w700, color: gc.textSecondary)),+ ],+ ),+ ),+ );++ Widget _tile(GymColors gc, int i) {+ final f = _fields[i];+ final on = i == _active;+ final unit = _bp ? '' : fit.measureUnit(_key);+ final value = unit.isEmpty ? _show(f.value) : '${_show(f.value)} $unit';+ return Semantics(+ button: true,+ selected: on,+ label: f.label,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => _pick(i),+ child: AnimatedContainer(+ duration: const Duration(milliseconds: 180),+ padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),+ decoration: BoxDecoration(+ color: on ? gc.bgRaised2 : Colors.transparent,+ borderRadius: BorderRadius.circular(16),+ border: Border.all(color: on ? gc.accent.withValues(alpha: 0.5) : gc.border.withValues(alpha: 0.6)),+ ),+ child: Column(children: [+ Text(f.label.toUpperCase(),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.2)),+ const SizedBox(height: 4),+ SizedBox(+ height: 32,+ child: Center(+ child: f.on+ ? Ltr(+ child: FitText(value,+ style: AppTheme.f(26, weight: FontWeight.w800, color: on ? gc.text : gc.textSecondary)),+ )+ : Text(t.bpPulseAdd, style: AppTheme.f(14, weight: FontWeight.w700, color: gc.accent)),+ ),+ ),+ ]),+ ),+ ),+ );+ }++ Widget _noteField(GymColors gc) => Container(+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(16)),+ child: TextField(+ controller: _note,+ maxLength: 200,+ textCapitalization: TextCapitalization.sentences,+ cursorColor: gc.accent,+ style: AppTheme.f(14.5, weight: FontWeight.w600, color: gc.text),+ decoration: InputDecoration(+ border: InputBorder.none,+ hintText: t.measureNoteHint,+ hintStyle: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.textTertiary),+ counterText: '',+ ),+ ),+ );++ Widget _iconButton(GymColors gc, IconData icon, String label, VoidCallback onTap, double size) => Semantics(+ button: true,+ label: label,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.all(8),+ child: Icon(icon, size: size, color: gc.textSecondary),+ ),+ ),+ );+@overrideWidget build(BuildContext context) {final gc = context.gc;final history = fit.measureHistory(_key);- final (lo, hi) = _range;+ final f = _field;return Container(decoration: sheetDecoration(gc),@@ -338,95 +505,85 @@ class _MeasureSheetState extends State<_MeasureSheet> {mainAxisSize: MainAxisSize.min,children: [SheetHandle(margin: const EdgeInsets.symmetric(vertical: 12)),- Padding(- padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- Row(children: [- Expanded(- child: Text(fit.measureTitle(_key),- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: AppTheme.f(17, weight: FontWeight.w800, color: gc.text)),- ),- if (fit.isCustomMeasure(_key))- Semantics(- button: true,- label: t.measureRename,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _rename,- child: Padding(- padding: const EdgeInsets.all(8),- child: Icon(PhosphorIconsRegular.pencilSimple, size: 19, color: gc.textSecondary),- ),- ),- ),- Semantics(- button: true,- label: fit.measureTitle(_key),- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _type,- child: Padding(- padding: const EdgeInsets.all(8),- child: Icon(PhosphorIconsRegular.keyboard, size: 20, color: gc.textSecondary),- ),+ Flexible(+ child: SingleChildScrollView(+ padding: const EdgeInsets.fromLTRB(20, 4, 20, 20),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ Row(children: [+ Expanded(+ child: Text(fit.measureTitle(_key),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(17, weight: FontWeight.w800, color: gc.text)),),- ),- ]),- const SizedBox(height: 6),- Center(- child: Ltr(child: Row(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.baseline,- textBaseline: TextBaseline.alphabetic,- children: [- RollingText(_show(_value),- style: AppTheme.f(54, weight: FontWeight.w800, color: gc.text, height: 1.1)),- const SizedBox(width: 6),- Text(fit.measureUnit(_key),- style: AppTheme.f(18, weight: FontWeight.w700, color: gc.textSecondary)),- ],- )),- ),- const SizedBox(height: 14),- RulerPicker(- value: _value.clamp(lo, hi),- min: lo,- max: hi,- step: _step,- majorEvery: _major,- label: (v) => '${v.round()}',- onChanged: (v) => setState(() => _value = v),- ),- const SizedBox(height: 18),- PrimaryButton(label: t.save, onTap: _save, height: 52),- if (history.isNotEmpty) ...[- const SizedBox(height: 22),- Text(t.measureHistory,- style: AppTheme.d(12,- weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),- const SizedBox(height: 10),- for (final m in history.take(6)) _historyRow(gc, m),- ],- if (fit.isCustomMeasure(_key)) ...[- const SizedBox(height: 10),- GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: _delete,- child: SizedBox(- height: 44,- child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [- Icon(PhosphorIconsRegular.trash, size: 16, color: gc.danger),- const SizedBox(width: 8),- Text(t.measureDelete, style: AppTheme.f(14, weight: FontWeight.w600, color: gc.danger)),+ if (fit.isCustomMeasure(_key))+ _iconButton(gc, PhosphorIconsRegular.pencilSimple, t.measureRename, _rename, 19),+ _iconButton(gc, PhosphorIconsRegular.keyboard, fit.measureTitle(_key), _type, 20),+ ]),+ if (fit.canSide(_key)) ...[+ const SizedBox(height: 8),+ Align(+ alignment: AlignmentDirectional.centerStart,+ child: SegToggle([+ SegOption(t.measureOneValue, !_sided, () => _setSided(false)),+ SegOption(t.eachSide, _sided, () => _setSided(true)),]),),+ ],+ const SizedBox(height: 10),+ if (_fields.length == 1)+ _bigValue(gc)+ else+ Row(children: [+ for (var i = 0; i < _fields.length; i++) ...[+ if (i > 0) const SizedBox(width: 8),+ Expanded(child: _tile(gc, i)),+ ],+ ]),+ const SizedBox(height: 14),+ RulerPicker(+ key: ValueKey('${_fields.length}-$_active'),+ value: f.value.clamp(f.lo, f.hi),+ min: f.lo,+ max: f.hi,+ step: f.step,+ majorEvery: f.major,+ label: (v) => '${v.round()}',+ onChanged: (v) => setState(() {+ f.value = v;+ f.on = true;+ }),),+ const SizedBox(height: 14),+ _noteField(gc),+ const SizedBox(height: 14),+ PrimaryButton(label: t.save, onTap: _save, height: 52),+ if (history.isNotEmpty) ...[+ const SizedBox(height: 22),+ Text(t.measureHistory,+ style: AppTheme.d(12, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),+ const SizedBox(height: 10),+ for (final m in history.take(8)) _historyRow(gc, m),+ ],+ if (fit.isCustomMeasure(_key)) ...[+ const SizedBox(height: 10),+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: _delete,+ child: SizedBox(+ height: 44,+ child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [+ Icon(PhosphorIconsRegular.trash, size: 16, color: gc.danger),+ const SizedBox(width: 8),+ Text(t.measureDelete, style: AppTheme.f(14, weight: FontWeight.w600, color: gc.danger)),+ ]),+ ),+ ),+ ],],- ],+ ),),),],@@ -438,12 +595,20 @@ class _MeasureSheetState extends State<_MeasureSheet> {Widget _historyRow(GymColors gc, BodyMeasure m) => Padding(padding: const EdgeInsets.symmetric(vertical: 7),child: Row(+ crossAxisAlignment: CrossAxisAlignment.start,children: [Expanded(- child: Text(t.shortDateYear(m.date), style: AppTheme.s(12.5, color: gc.textSecondary)),+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [+ Text('${t.shortDateYear(m.date)} · ${t.clockTime(m.date)}',+ style: AppTheme.s(12.5, color: gc.textSecondary)),+ if (m.note.isNotEmpty) ...[+ const SizedBox(height: 3),+ Text(m.note, style: AppTheme.s(12.5, color: gc.textTertiary, height: 1.35)),+ ],+ ]),),- Text(fit.measureLabel(m.key, m.value),- style: AppTheme.s(13.5, weight: FontWeight.w600, color: gc.text)),+ const SizedBox(width: 10),+ Ltr(child: Text(fit.measureEntryLabel(m), style: AppTheme.s(13.5, weight: FontWeight.w600, color: gc.text))),const SizedBox(width: 8),Semantics(button: true,diff --git a/lib/screens/progress_screen.dart b/lib/screens/progress_screen.dartindex aecba25..79e7e55 100644--- a/lib/screens/progress_screen.dart+++ b/lib/screens/progress_screen.dart@@ -901,7 +901,7 @@ class ProgressScreen extends StatelessWidget {overflow: TextOverflow.ellipsis,style: AppTheme.s(10.5, weight: FontWeight.w600, color: gc.textTertiary)),const SizedBox(height: 3),- Text(fit.measureLabel(key, latest.value),+ Text(fit.isPressure(key) ? '${fit.measureHeadline(latest)} ${fit.measureUnit(key)}' : fit.measureLabel(key, latest.value),style: AppTheme.d(15, weight: FontWeight.w700, color: gc.text)),],),diff --git a/lib/screens/tool_detail_screen.dart b/lib/screens/tool_detail_screen.dartindex b0af709..54d6870 100644--- a/lib/screens/tool_detail_screen.dart+++ b/lib/screens/tool_detail_screen.dart@@ -161,14 +161,26 @@ class ToolDetailScreen extends StatelessWidget {_macros(gc),];case 'bf':+ final male = fit.bfSex == 'male';+ final girth = male ? t.bfAbdomen : t.bfWaistNarrow;return [- ToolRow(label: t.heightLabel, control: StepperControl(value: fit.heightLabel(fit.bfHeight), onDec: () => fit.bumpBfHeight(-fit.heightStep), onInc: () => fit.bumpBfHeight(fit.heightStep), onEdit: () => _editNumber(context, title: t.heightLabel, current: fit.toDisplayCm(fit.bfHeight), decimal: true, apply: (v) => fit.bumpBfHeight(fit.fromDisplayCm(v) - fit.bfHeight)))),+ ToolRow(+ label: t.sexLabel,+ control: SegToggle([+ SegOption(t.male, male, () => fit.setBfSex('male')),+ SegOption(t.female, !male, () => fit.setBfSex('female')),+ ]),+ ),const SizedBox(height: 10),- ToolRow(label: t.neck, control: StepperControl(value: fit.cmLabel(fit.bfNeck), onDec: () => fit.bumpBfNeck(-fit.girthStep), onInc: () => fit.bumpBfNeck(fit.girthStep), onEdit: () => _editNumber(context, title: t.neck, current: fit.toDisplayCm(fit.bfNeck), decimal: true, apply: (v) => fit.bumpBfNeck(fit.fromDisplayCm(v) - fit.bfNeck)))),+ ToolRow(label: t.heightLabel, control: StepperControl(value: fit.heightLabel(fit.bfHeight), onDec: () => fit.bumpBfHeight(-fit.heightStep), onInc: () => fit.bumpBfHeight(fit.heightStep), onEdit: () => _editNumber(context, title: t.heightLabel, current: fit.toDisplayCm(fit.bfHeight), decimal: true, apply: (v) => fit.bumpBfHeight(fit.fromDisplayCm(v) - fit.bfHeight)))),const SizedBox(height: 10),- ToolRow(label: t.waist, control: StepperControl(value: fit.cmLabel(fit.bfWaist), onDec: () => fit.bumpBfWaist(-fit.girthStep), onInc: () => fit.bumpBfWaist(fit.girthStep), onEdit: () => _editNumber(context, title: t.waist, current: fit.toDisplayCm(fit.bfWaist), decimal: true, apply: (v) => fit.bumpBfWaist(fit.fromDisplayCm(v) - fit.bfWaist)))),+ ToolRow(label: t.bfNeckBelow, control: StepperControl(value: fit.cmLabel(fit.bfNeck), onDec: () => fit.bumpBfNeck(-fit.girthStep), onInc: () => fit.bumpBfNeck(fit.girthStep), onEdit: () => _editNumber(context, title: t.bfNeckBelow, current: fit.toDisplayCm(fit.bfNeck), decimal: true, apply: (v) => fit.bumpBfNeck(fit.fromDisplayCm(v) - fit.bfNeck)))),const SizedBox(height: 10),- ToolRow(label: t.hip, control: StepperControl(value: fit.cmLabel(fit.bfHip), onDec: () => fit.bumpBfHip(-fit.girthStep), onInc: () => fit.bumpBfHip(fit.girthStep), onEdit: () => _editNumber(context, title: t.hip, current: fit.toDisplayCm(fit.bfHip), decimal: true, apply: (v) => fit.bumpBfHip(fit.fromDisplayCm(v) - fit.bfHip)))),+ ToolRow(label: girth, control: StepperControl(value: fit.cmLabel(fit.bfWaist), onDec: () => fit.bumpBfWaist(-fit.girthStep), onInc: () => fit.bumpBfWaist(fit.girthStep), onEdit: () => _editNumber(context, title: girth, current: fit.toDisplayCm(fit.bfWaist), decimal: true, apply: (v) => fit.bumpBfWaist(fit.fromDisplayCm(v) - fit.bfWaist)))),+ if (!male) ...[+ const SizedBox(height: 10),+ ToolRow(label: t.bfHipWide, control: StepperControl(value: fit.cmLabel(fit.bfHip), onDec: () => fit.bumpBfHip(-fit.girthStep), onInc: () => fit.bumpBfHip(fit.girthStep), onEdit: () => _editNumber(context, title: t.bfHipWide, current: fit.toDisplayCm(fit.bfHip), decimal: true, apply: (v) => fit.bumpBfHip(fit.fromDisplayCm(v) - fit.bfHip)))),+ ],];case 'plate':return [diff --git a/lib/state/measures_state.dart b/lib/state/measures_state.dartindex a0c5de8..04d90d9 100644--- a/lib/state/measures_state.dart+++ b/lib/state/measures_state.dart@@ -4,8 +4,22 @@ const double _cmPerInch = 2.54;mixin MeasuresState on FitCore {final List<CustomMeasure> customMeasures = [];+ final Set<String> sidedMeasures = {};int measureEveryDays = 0;+ bool isPressure(String key) => key == 'bp';++ bool canSide(String key) => kSidedMeasureKeys.contains(key);++ bool isSidedMeasure(String key) => canSide(key) && sidedMeasures.contains(key);++ void toggleSidedMeasure(String key) {+ if (!canSide(key)) return;+ if (!sidedMeasures.remove(key)) sidedMeasures.add(key);+ _persist();+ notifyListeners();+ }+bool get isInches => units == 'lb';String get lengthUnit => isInches ? 'in' : 'cm';@@ -27,11 +41,11 @@ mixin MeasuresState on FitCore {bool isPercent(String key) => key == 'bodyfat';- double toDisplayMeasure(String key, double raw) =>- isPercent(key) || isFreeMeasure(key) || !isInches ? raw : raw / _cmPerInch;+ bool _plain(String key) => isPercent(key) || isPressure(key) || isFreeMeasure(key) || !isInches;++ double toDisplayMeasure(String key, double raw) => _plain(key) ? raw : raw / _cmPerInch;- double fromDisplayMeasure(String key, double shown) =>- isPercent(key) || isFreeMeasure(key) || !isInches ? shown : shown * _cmPerInch;+ double fromDisplayMeasure(String key, double shown) => _plain(key) ? shown : shown * _cmPerInch;double toDisplayCm(double cm) => isInches ? cm / _cmPerInch : cm;@@ -53,6 +67,7 @@ mixin MeasuresState on FitCore {String measureUnit(String key) {if (isPercent(key)) return '%';+ if (isPressure(key)) return 'mmHg';final c = customMeasure(key);if (c != null && !c.length) return c.unit;return lengthUnit;@@ -65,18 +80,36 @@ mixin MeasuresState on FitCore {return unit.isEmpty ? measureValue(key, raw) : '${measureValue(key, raw)} $unit';}+ String measureHeadline(BodyMeasure m) =>+ isPressure(m.key) && m.low != null ? '${m.value.round()}/${m.low!.round()}' : measureValue(m.key, m.value);++ String measureEntryLabel(BodyMeasure m) {+ final unit = measureUnit(m.key);+ if (isPressure(m.key)) {+ final bp = '${measureHeadline(m)} $unit';+ return m.pulse == null ? bp : '$bp · ${m.pulse} ${t.healthBpm}';+ }+ if (m.sided) {+ return '${t.measureLeftShort} ${measureValue(m.key, m.left!)} · ${t.measureRightShort} ${measureValue(m.key, m.right!)} $unit';+ }+ return measureLabel(m.key, m.value);+ }+List<BodyMeasure> measureHistory(String key) {final out = measures.where((m) => m.key == key).toList()..sort((a, b) => b.date.compareTo(a.date));return out;}+ double lastGirth(String key) => latestMeasure(key)?.value ?? 0;+BodyMeasure? latestMeasure(String key) {final h = measureHistory(key);return h.isEmpty ? null : h.first;}double? measureChange(String key) {+ if (isPressure(key)) return null;final h = measureHistory(key);if (h.length < 2) return null;return _round1(toDisplayMeasure(key, h.first.value) - toDisplayMeasure(key, h[1].value));@@ -90,12 +123,28 @@ mixin MeasuresState on FitCore {bool get hasMeasures => measures.isNotEmpty;- void addMeasure(String key, double shown, {DateTime? date}) {- if (!allMeasureKeys.contains(key) || shown <= 0) return;+ void addMeasure(String key, double shown, {DateTime? date, String note = '', double? left, double? right}) {+ if (!allMeasureKeys.contains(key) || isPressure(key)) return;+ final both = left != null && right != null && left > 0 && right > 0;+ if (!both && shown <= 0) return;final when = date ?? DateTime.now();- final raw = isFreeMeasure(key) ? (shown * 100).round() / 100 : _round1(fromDisplayMeasure(key, shown));+ double raw(double v) => isFreeMeasure(key) ? (v * 100).round() / 100 : _round1(fromDisplayMeasure(key, v));+ final l = both ? raw(left) : null;+ final r = both ? raw(right) : null;+ final value = both ? _round1((l! + r!) / 2) : raw(shown);measures.removeWhere((m) => m.key == key && _dayKey(m.date) == _dayKey(when));- measures.add(BodyMeasure(when, key, raw));+ measures.add(BodyMeasure(when, key, value, note: _cut(note.trim(), 200), left: l, right: r));+ _syncMeasureReminder();+ _persist();+ notifyListeners();+ }++ void addPressure(int high, int low, {int? pulse, String note = '', DateTime? date}) {+ if (high <= 0 || low <= 0) return;+ final when = date ?? DateTime.now();+ measures.removeWhere((m) => m.key == 'bp' && m.date.difference(when).inMinutes.abs() < 1);+ measures.add(BodyMeasure(when, 'bp', high.toDouble(),+ low: low.toDouble(), pulse: pulse != null && pulse > 0 ? pulse : null, note: _cut(note.trim(), 200)));_syncMeasureReminder();_persist();notifyListeners();@@ -188,11 +237,15 @@ mixin MeasuresState on FitCore {if (e is Map) ?CustomMeasure.fromJson(e.cast<String, dynamic>()),]);measureEveryDays = ((data['measureEvery'] as num?)?.toInt() ?? 0).clamp(0, 365);+ sidedMeasures+ ..clear()+ ..addAll([for (final k in (data['measureSides'] as List?) ?? const []) if (k is String && canSide(k)) k]);}Map<String, dynamic> customMeasuresJson() => {if (customMeasures.isNotEmpty) 'customMeasures': customMeasures.map((c) => c.toJson()).toList(),if (measureEveryDays > 0) 'measureEvery': measureEveryDays,+ if (sidedMeasures.isNotEmpty) 'measureSides': sidedMeasures.toList(),};void goMeasures() => pushRoute('measures');diff --git a/lib/state/tools_state.dart b/lib/state/tools_state.dartindex 23b24bf..e335eaf 100644--- a/lib/state/tools_state.dart+++ b/lib/state/tools_state.dart@@ -63,6 +63,17 @@ mixin ToolsState on FitCore {double bestLift(String id) => 0;+ double lastGirth(String key) => 0;++ void _seedBf() {+ final neck = lastGirth('neck');+ final waist = lastGirth(bfSex == 'male' ? 'abdomen' : 'waist');+ final hips = lastGirth('hips');+ if (neck > 0) bfNeck = _clamp(neck, 20, 60);+ if (waist > 0) bfWaist = _clamp(waist, 40, 200);+ if (hips > 0) bfHip = _clamp(hips, 40, 200);+ }+void _seedDots() {if (_dotsSeeded) return;_dotsSeeded = true;@@ -76,12 +87,14 @@ mixin ToolsState on FitCore {void openTool(String id) {if (id == 'dots' || id == 'wilks') _seedDots();+ if (id == 'bf') _seedBf();activeToolId = id;pushRoute('tools-detail');}void selectTool(String id) {if (id == 'dots' || id == 'wilks') _seedDots();+ if (id == 'bf') _seedBf();activeToolId = id;notifyListeners();}@@ -271,7 +284,11 @@ mixin ToolsState on FitCore {void bumpBfHip(double d) { bfHip = _clamp(bfHip + d, 40, 200); notifyListeners(); }- void setBfSex(String s) { bfSex = s; notifyListeners(); }+ void setBfSex(String s) {+ bfSex = s;+ _seedBf();+ notifyListeners();+ }void bumpPlateTarget(double d) { plateTarget = _clamp(plateTarget + d, 0, null); notifyListeners(); }diff --git a/lib/widgets/ui_kit.dart b/lib/widgets/ui_kit.dartindex 95820de..302c13f 100644--- a/lib/widgets/ui_kit.dart+++ b/lib/widgets/ui_kit.dart@@ -885,13 +885,19 @@ class ToolRow extends StatelessWidget {constraints: const BoxConstraints(minHeight: 56),child: Padding(padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),- child: Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Flexible(child: Text(sentenceCase(label), style: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.text))),- const SizedBox(width: 12),- control,- ],+ child: LayoutBuilder(+ builder: (context, box) => Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ Flexible(+ child: Text(sentenceCase(label), style: AppTheme.f(14.5, weight: FontWeight.w500, color: gc.text))),+ const SizedBox(width: 12),+ ConstrainedBox(+ constraints: BoxConstraints(maxWidth: math.max(0.0, box.maxWidth - 84)),+ child: FittedBox(fit: BoxFit.scaleDown, alignment: AlignmentDirectional.centerEnd, child: control),+ ),+ ],+ ),),),);diff --git a/test/calculators_test.dart b/test/calculators_test.dartindex 4d60a5e..8485011 100644--- a/test/calculators_test.dart+++ b/test/calculators_test.dart@@ -133,6 +133,22 @@ void main() {});group('Body fat (US Navy)', () {+ test('se rellena con las últimas medidas: abdomen en hombres, cintura y cadera en mujeres (#410)', () {+ fit.resetAllData();+ fit.addMeasure('neck', 39);+ fit.addMeasure('abdomen', 91);+ fit.addMeasure('waist', 72);+ fit.addMeasure('hips', 99);+ expect(fit.allMeasureKeys, contains('abdomen'));+ fit.bfSex = 'male';+ fit.selectTool('bf');+ expect(fit.bfNeck, 39);+ expect(fit.bfWaist, 91);+ fit.setBfSex('female');+ expect(fit.bfWaist, 72);+ expect(fit.bfHip, 99);+ });+test('male 175 cm, neck 38, waist 84 → 16.2%', () {fit.bfSex = 'male';fit.bfHeight = 175;diff --git a/test/measures_test.dart b/test/measures_test.dartindex 43db96c..3087ca3 100644--- a/test/measures_test.dart+++ b/test/measures_test.dart@@ -134,4 +134,46 @@ void main() {fit.setMeasureEvery(0);expect(fit.nextMeasureDue, isNull);});+ test('a note and both sides are kept, and the average drives the trend (#410)', () {+ fit.toggleSidedMeasure('arm');+ expect(fit.isSidedMeasure('arm'), isTrue);+ expect(fit.canSide('waist'), isFalse);+ fit.addMeasure('arm', 0, left: 36, right: 37, note: 'morning, pumped');+ final m = fit.latestMeasure('arm')!;+ expect(m.left, 36);+ expect(m.right, 37);+ expect(m.value, closeTo(36.5, 0.001));+ expect(m.note, 'morning, pumped');+ expect(fit.measureEntryLabel(m), contains('36'));+ expect(fit.measureEntryLabel(m), contains('37'));+ });++ test('blood pressure keeps the whole reading, the pulse and several a day', () {+ final morning = DateTime.now().subtract(const Duration(hours: 3));+ fit.addPressure(128, 84, pulse: 66, note: 'after coffee', date: morning);+ fit.addPressure(118, 76);+ expect(fit.measureHistory('bp'), hasLength(2));+ final first = fit.measureHistory('bp').last;+ expect(fit.measureHeadline(first), '128/84');+ expect(fit.measureEntryLabel(first), contains('66'));+ expect(fit.measureUnit('bp'), 'mmHg');+ expect(fit.measureChange('bp'), isNull);+ fit.setUnits('lb');+ expect(fit.measureHeadline(fit.latestMeasure('bp')!), '118/76');+ });++ test('notes, sides and blood pressure survive a reload', () {+ fit.toggleSidedMeasure('thigh');+ fit.addMeasure('thigh', 0, left: 58, right: 57.5, note: 'n');+ fit.addPressure(120, 80, pulse: 70);+ fit.persistNow();+ fit.loadFromStore();+ expect(fit.isSidedMeasure('thigh'), isTrue);+ final th = fit.latestMeasure('thigh')!;+ expect(th.right, 57.5);+ expect(th.note, 'n');+ final bp = fit.latestMeasure('bp')!;+ expect(bp.low, 80);+ expect(bp.pulse, 70);+ });}