Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Pick a portion of the batch when logging
InlitX1274d667e679
diff --git a/lib/screens/nutrition/prep.dart b/lib/screens/nutrition/prep.dartindex 3447deb..0a6888d 100644--- a/lib/screens/nutrition/prep.dart+++ b/lib/screens/nutrition/prep.dart@@ -242,7 +242,7 @@ class _BatchLogSheet extends StatefulWidget {class _BatchLogSheetState extends State<_BatchLogSheet> {late Meal _meal = widget.meal;- bool _byShare = true;+ int _mode = 0;double _share = 0.25;double _grams = 300;@@ -250,7 +250,36 @@ class _BatchLogSheetState extends State<_BatchLogSheet> {double get _gramStep => fit.isLb ? _ozOf(false) : 25;- double get _take => _byShare ? _b.leftGrams * _share : math.min(_grams, _b.leftGrams);+ double get _portion {+ final b = _b;+ final one = b.totalGrams / b.portions;+ return b.leftGrams - one < one * 0.15 ? b.leftGrams : math.min(one, b.leftGrams);+ }++ double get _take => switch (_mode) {+ 0 => _portion,+ 1 => _b.leftGrams * _share,+ _ => math.min(_grams, _b.leftGrams),+ };++ Widget _chip(GymColors gc, bool on, String label, String sub, VoidCallback onTap) => Pressable(+ onTap: onTap,+ scale: 0.94,+ child: AnimatedContainer(+ duration: const Duration(milliseconds: 160),+ margin: const EdgeInsets.symmetric(horizontal: 3),+ padding: const EdgeInsets.symmetric(vertical: 11),+ decoration: BoxDecoration(+ color: on ? gc.accentSoft : gc.bgRaised2,+ borderRadius: BorderRadius.circular(14),+ border: Border.all(color: on ? gc.accent.withValues(alpha: 0.6) : Colors.transparent),+ ),+ child: Column(children: [+ Text(label, style: AppTheme.f(13, weight: FontWeight.w800, color: on ? gc.accent : gc.text)),+ Text(sub, style: AppTheme.f(10, weight: FontWeight.w600, color: gc.textTertiary)),+ ]),+ ),+ );Future<void> _weigh() async {final k = fit.isLb ? _ozOf(false) : 1.0;@@ -281,39 +310,29 @@ class _BatchLogSheetState extends State<_BatchLogSheet> {const SizedBox(height: 14),Center(child: SegToggle([- SegOption(t.prepOfWhatsLeft, _byShare, () => setState(() => _byShare = true)),- SegOption(_amtUnit(false), !_byShare, () => setState(() {+ SegOption(t.prepPortions, _mode == 0, () => setState(() => _mode = 0)),+ SegOption(t.prepOfWhatsLeft, _mode == 1, () => setState(() => _mode = 1)),+ SegOption(_amtUnit(false), _mode == 2, () => setState(() {_grams = _take.roundToDouble();- _byShare = false;+ _mode = 2;})),]),),const SizedBox(height: 12),- if (_byShare)+ if (_mode == 0)+ Row(children: [+ for (final n in const [2, 3, 4, 5, 6])+ Expanded(+ child: _chip(gc, n == b.portions, '1/$n', _amount(b.totalGrams / n, false),+ () => fit.setBatchPortions(b.id, n)),+ ),+ ])+ else if (_mode == 1)Row(children: [for (final s in shares)Expanded(- child: Pressable(- onTap: () => setState(() => _share = s),- scale: 0.94,- child: AnimatedContainer(- duration: const Duration(milliseconds: 160),- margin: const EdgeInsets.symmetric(horizontal: 3),- padding: const EdgeInsets.symmetric(vertical: 11),- decoration: BoxDecoration(- color: (s - _share).abs() < 0.001 ? gc.accentSoft : gc.bgRaised2,- borderRadius: BorderRadius.circular(14),- border: Border.all(- color: (s - _share).abs() < 0.001 ? gc.accent.withValues(alpha: 0.6) : Colors.transparent),- ),- child: Column(children: [- Text(s == 1 ? t.prepAll : '${(s * 100).round()} %',- style: AppTheme.f(13, weight: FontWeight.w800, color: (s - _share).abs() < 0.001 ? gc.accent : gc.text)),- Text(_amount(b.leftGrams * s, false),- style: AppTheme.f(10, weight: FontWeight.w600, color: gc.textTertiary)),- ]),- ),- ),+ child: _chip(gc, (s - _share).abs() < 0.001, s == 1 ? t.prepAll : '${(s * 100).round()} %',+ _amount(b.leftGrams * s, false), () => setState(() => _share = s)),),])else