Skip to content

Offline gym log for Android. No account, no ads, no internet.

Nutrition: fat types, cleaner layout and motion

InlitX1aac8376cf1b
diff --git a/lib/screens/nutrition/cards.dart b/lib/screens/nutrition/cards.dart
index 4f612ee..973b0c2 100644
--- a/lib/screens/nutrition/cards.dart
+++ b/lib/screens/nutrition/cards.dart
@@ -26,10 +26,15 @@ class _HeroCard extends StatelessWidget {
);
Widget macro(IconData icon, String label, double value, int goal, Color color) => Expanded(
child: Column(children: [
- Text.rich(TextSpan(children: [
- TextSpan(text: '${value.round()}', style: AppTheme.f(15, weight: FontWeight.w800, color: gc.text)),
- TextSpan(text: '/${goal}g', style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary)),
- ])),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.baseline,
+ textBaseline: TextBaseline.alphabetic,
+ children: [
+ RollingText('${value.round()}', style: AppTheme.f(15, weight: FontWeight.w800, color: gc.text)),
+ Text('/${goal}g', style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary)),
+ ],
+ ),
const SizedBox(height: 7),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
@@ -142,10 +147,14 @@ class _RingCard extends StatelessWidget {
FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
- child: Text.rich(TextSpan(children: [
- TextSpan(text: value, style: AppTheme.f(21, weight: FontWeight.w800, color: gc.text, height: 1.05)),
- TextSpan(text: ' g', style: AppTheme.f(12, weight: FontWeight.w700, color: gc.textSecondary)),
- ])),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.baseline,
+ textBaseline: TextBaseline.alphabetic,
+ children: [
+ RollingText(value, style: AppTheme.f(21, weight: FontWeight.w800, color: gc.text, height: 1.05)),
+ Text(' g', style: AppTheme.f(12, weight: FontWeight.w700, color: gc.textSecondary)),
+ ],
+ ),
),
const SizedBox(height: 2),
Text(sub, maxLines: 1, style: AppTheme.f(11, weight: FontWeight.w600, color: gc.textSecondary)),
@@ -531,10 +540,11 @@ class _FatTypesCard extends StatelessWidget {
Text('${_g(total.fat)} g', style: AppTheme.f(13, weight: FontWeight.w800, color: gc.text)),
]),
const SizedBox(height: 14),
- _SplitBar(parts: [(total.sat, gc.warn), (total.mono, gc.sage), (total.poly, gc.info)]),
+ _SplitBar(parts: [(total.sat, gc.warn), (total.trans, gc.danger), (total.mono, gc.sage), (total.poly, gc.info)]),
const SizedBox(height: 14),
Row(children: [
legend(gc.warn, t.fatSaturated, total.sat),
+ if (total.trans > 0) legend(gc.danger, t.fatTrans, total.trans),
legend(gc.sage, t.fatMono, total.mono),
legend(gc.info, t.fatPoly, total.poly),
]),
diff --git a/lib/screens/nutrition/food.dart b/lib/screens/nutrition/food.dart
index 29c3003..e39b140 100644
--- a/lib/screens/nutrition/food.dart
+++ b/lib/screens/nutrition/food.dart
@@ -563,7 +563,7 @@ class _FoodInfoSheet extends StatelessWidget {
showFoodEditor(context, food: f.isLibrary ? null : f, from: f.isLibrary ? f : null, meal: meal);
},
),
- if (m.fat >= 1 && m.sat + m.mono + m.poly > 0) ...[const SizedBox(height: 12), _FatTypesCard(of: m)],
+ if (m.fat >= 1 && m.hasFatTypes) ...[const SizedBox(height: 12), _FatTypesCard(of: m)],
if (m.protein >= 5 && m.aminoScores.isNotEmpty) ...[const SizedBox(height: 12), _QualityCard(of: m)],
const SizedBox(height: 18),
PrimaryButton(
@@ -1294,6 +1294,7 @@ class _EntryValuesSheetState extends State<_EntryValuesSheet> {
sodium: old.sodium,
animal: old.protein <= 0 ? 0 : old.animal / old.protein * m.protein,
sat: old.sat,
+ trans: old.trans,
mono: old.mono,
poly: old.poly,
aminoProtein: old.protein <= 0 ? 0 : old.aminoProtein / old.protein * m.protein,
@@ -1429,6 +1430,10 @@ Macros _macrosOf(
TextEditingController? fiber,
TextEditingController? sugar,
TextEditingController? sodium,
+ TextEditingController? sat,
+ TextEditingController? trans,
+ TextEditingController? mono,
+ TextEditingController? poly,
}) {
final protein = _read(p), carbs = _read(c), fat = _read(f);
var kcal = fit.kcalFromShown(_read(k));
@@ -1441,6 +1446,10 @@ Macros _macrosOf(
fiber: fiber == null ? 0 : _read(fiber),
sugar: sugar == null ? 0 : _read(sugar),
sodium: sodium == null ? 0 : _read(sodium),
+ sat: sat == null ? 0 : _read(sat),
+ trans: trans == null ? 0 : _read(trans),
+ mono: mono == null ? 0 : _read(mono),
+ poly: poly == null ? 0 : _read(poly),
);
}
@@ -1732,7 +1741,11 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
late final _fi = TextEditingController(text: _seed(_base?.macros.fiber ?? 0));
late final _su = TextEditingController(text: _seed(_base?.macros.sugar ?? 0));
late final _na = TextEditingController(text: _seed(_base?.macros.sodium ?? 0));
- late bool _extras = _base?.macros.hasExtras ?? false;
+ late final _sat = TextEditingController(text: _seed(_base?.macros.sat ?? 0));
+ late final _trans = TextEditingController(text: _seed(_base?.macros.trans ?? 0));
+ late final _mono = TextEditingController(text: _seed(_base?.macros.mono ?? 0));
+ late final _poly = TextEditingController(text: _seed(_base?.macros.poly ?? 0));
+ late bool _extras = (_base?.macros.hasExtras ?? false) || (_base?.macros.hasFatTypes ?? false);
late bool _shake = widget.asShake || (widget.food != null && fit.isShakeFood(widget.food!.id));
late double _animalShare = _shareOf(_base?.macros);
late FoodCat? _cat = _base?.cat;
@@ -1752,7 +1765,7 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
@override
void dispose() {
- for (final c in [_name, _serving, _grams, _kcal, _p, _c, _f, _fi, _su, _na]) {
+ for (final c in [_name, _serving, _grams, _kcal, _p, _c, _f, _fi, _su, _na, _sat, _trans, _mono, _poly]) {
c.dispose();
}
_dropDrafts();
@@ -1767,7 +1780,8 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
}
var grams = (_read(_grams) * _k).clamp(0, 5000).toDouble();
if (_per100 && grams <= 0) grams = 100;
- final typed = _macrosOf(_kcal, _p, _c, _f, fiber: _fi, sugar: _su, sodium: _na);
+ final typed = _macrosOf(_kcal, _p, _c, _f,
+ fiber: _fi, sugar: _su, sodium: _na, sat: _sat, trans: _trans, mono: _mono, poly: _poly);
final saved = fit.saveFood(
id: widget.food?.id,
name: name,
@@ -1796,7 +1810,7 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
final grams = _read(_grams) * _k;
if (grams > 0) {
final k = on ? 100 / grams : grams / 100;
- for (final c in [_kcal, _p, _c, _f, _fi, _su, _na]) {
+ for (final c in [_kcal, _p, _c, _f, _fi, _su, _na, _sat, _trans, _mono, _poly]) {
final v = _read(c);
if (v > 0) c.text = _seed(v * k);
}
@@ -1845,6 +1859,7 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
sodium: m.sodium,
animal: m.protein * _animalShare,
sat: m.sat,
+ trans: m.trans,
mono: m.mono,
poly: m.poly,
aminoProtein: m.aminoProtein,
@@ -1865,9 +1880,10 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
sugar: m.sugar,
sodium: m.sodium,
animal: old.animal * k,
- sat: old.fat <= 0 ? 0 : old.sat * m.fat / old.fat,
- mono: old.fat <= 0 ? 0 : old.mono * m.fat / old.fat,
- poly: old.fat <= 0 ? 0 : old.poly * m.fat / old.fat,
+ sat: m.sat,
+ trans: m.trans,
+ mono: m.mono,
+ poly: m.poly,
aminoProtein: old.aminoProtein * k,
amino: [for (final a in old.amino) a * k],
);
@@ -1968,7 +1984,7 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
const SizedBox(height: 8),
_MacroInputs(kcal: _kcal, protein: _p, carbs: _c, fat: _f),
const SizedBox(height: 8),
- if (_extras)
+ if (_extras) ...[
Row(children: [
Expanded(child: _NumberField(label: t.fiberLabel.toUpperCase(), controller: _fi, color: gc.sage)),
const SizedBox(width: 8),
@@ -1978,8 +1994,25 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
child: _NumberField(
label: t.sodiumLabel.toUpperCase(), controller: _na, color: gc.textSecondary, suffix: 'mg'),
),
- ])
- else
+ ]),
+ const SizedBox(height: 14),
+ Text(t.fatTypes.toUpperCase(),
+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.1)),
+ const SizedBox(height: 8),
+ Row(children: [
+ Expanded(child: _NumberField(label: t.fatSaturated.toUpperCase(), controller: _sat, color: gc.warn)),
+ const SizedBox(width: 8),
+ Expanded(child: _NumberField(label: t.fatTrans.toUpperCase(), controller: _trans, color: gc.danger)),
+ ]),
+ const SizedBox(height: 8),
+ Row(children: [
+ Expanded(child: _NumberField(label: t.fatMono.toUpperCase(), controller: _mono, color: gc.sage)),
+ const SizedBox(width: 8),
+ Expanded(child: _NumberField(label: t.fatPoly.toUpperCase(), controller: _poly, color: gc.info)),
+ ]),
+ const SizedBox(height: 6),
+ Text(t.fatTypesHint, textAlign: TextAlign.center, style: AppTheme.s(11.5, color: gc.textTertiary, height: 1.4)),
+ ] else
Center(
child: TextButton(
onPressed: () => setState(() => _extras = true),
diff --git a/lib/screens/nutrition_screen.dart b/lib/screens/nutrition_screen.dart
index ff8edc2..f5fcfd3 100644
--- a/lib/screens/nutrition_screen.dart
+++ b/lib/screens/nutrition_screen.dart
@@ -17,6 +17,7 @@ import '../services/sticker_cutout.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
+import '../widgets/entrance.dart';
import '../widgets/charts.dart';
import '../widgets/dialogs.dart';
import '../widgets/glass.dart';
@@ -169,7 +170,10 @@ class _NutritionScreenState extends State<NutritionScreen> {
if (on(Tracker.week)) _WeekTile(),
if (on(Tracker.weight)) _WeightTile(),
];
- return SafeArea(
+ var order = 0;
+ return RiseScope(
+ id: 'nutrition',
+ child: SafeArea(
bottom: false,
child: ListView(
clipBehavior: Clip.none,
@@ -183,12 +187,6 @@ class _NutritionScreenState extends State<NutritionScreen> {
onBack: fit.backFromNutrition,
badge: BetaTag(t.sectionBeta),
actions: [
- RoundAction(
- label: t.nutritionAboutTitle,
- onTap: () => showNutritionAbout(context),
- child: Icon(PhosphorIconsRegular.question, size: 17, color: gc.textSecondary),
- ),
- const SizedBox(width: 8),
RoundAction(
label: t.trackersTitle,
onTap: () => showTrackersSheet(context),
@@ -241,9 +239,10 @@ class _NutritionScreenState extends State<NutritionScreen> {
for (final d in detail) ...[const SizedBox(height: 12), d],
],
])
- w is SizedBox ? w : _Keep(child: w),
+ w is SizedBox ? w : _Keep(child: Rise(index: order++, child: w)),
],
),
+ ),
);
}
}
@@ -278,20 +277,31 @@ class _Heading extends StatelessWidget {
@override
Widget build(BuildContext context) {
final gc = context.gc;
- return Row(
- children: [
- Expanded(child: Text(titleCase(title), style: AppTheme.f(19, color: gc.text))),
- if (action != null)
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: onAction,
- child: Row(children: [
- Icon(PhosphorIconsBold.plus, size: 13, color: gc.accent),
- const SizedBox(width: 5),
- Text(action!, style: AppTheme.f(13, weight: FontWeight.w700, color: gc.accent)),
- ]),
+ return Padding(
+ padding: const EdgeInsets.only(left: 4),
+ child: Row(
+ children: [
+ Expanded(
+ child: Text(title.toUpperCase(),
+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.4)),
),
- ],
+ if (action != null)
+ Pressable(
+ onTap: onAction!,
+ scale: 0.94,
+ child: Container(
+ height: 30,
+ padding: const EdgeInsets.symmetric(horizontal: 12),
+ decoration: BoxDecoration(color: gc.bgRaised, borderRadius: BorderRadius.circular(15)),
+ child: Row(mainAxisSize: MainAxisSize.min, children: [
+ Icon(PhosphorIconsBold.plus, size: 12, color: gc.text),
+ const SizedBox(width: 5),
+ Text(action!, style: AppTheme.f(12.5, weight: FontWeight.w700, color: gc.text)),
+ ]),
+ ),
+ ),
+ ],
+ ),
);
}
}
@@ -397,8 +407,8 @@ Widget _sheetFrame(BuildContext context, List<Widget> children, {double heightFa
height: heightFactor > 0 ? MediaQuery.of(context).size.height * heightFactor : null,
padding: sheetPad(context, bottom: 18),
decoration: BoxDecoration(
- color: gc.bgRaised,
- borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ color: fit.dark ? Color.lerp(gc.bg, gc.bgRaised, 0.55) : gc.bg,
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(32)),
),
child: SingleChildScrollView(
child: Column(
diff --git a/lib/state/nutrition_state.dart b/lib/state/nutrition_state.dart
index cd4a0d1..1bb3ac9 100644
--- a/lib/state/nutrition_state.dart
+++ b/lib/state/nutrition_state.dart
@@ -89,7 +89,7 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
bool isTrainingDay(DateTime day) {
final key = _dayKey(day);
- if (sessions.any((s) => _dayKey(s.date) == key)) return true;
+ if (_sessionsOnDay(key).isNotEmpty || _sessionsOnDay(shiftDays(key, -1)).any((s) => _dayKey(s.date) == key)) return true;
if (key != _dayKey(DateTime.now())) return false;
return hasPlanOn(key);
}
@@ -106,7 +106,7 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
int burnedOn(DateTime day) {
final key = _dayKey(day);
var kcal = 0.0;
- for (final s in sessions.where((s) => _dayKey(s.day) == key)) {
+ for (final s in _sessionsOnDay(key)) {
var cardioSec = 0;
for (final e in s.exercises) {
final c = cardioKcal(s, e);
@@ -1352,7 +1352,7 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
Map<String, dynamic> nutritionJson() => {
'foods': foods.map((f) => f.toJson()).toList(),
- 'log': foodLog.map((e) => e.toJson()).toList(),
+ 'log': _stored('log', foodLog, (e) => e.toJson()),
'water': waterLog.map((w) => w.toJson()).toList(),
'supps': supplements.map((s) => s.toJson()).toList(),
'taken': supplementsTaken.map((k, v) => MapEntry(k, v.toList())),
diff --git a/lib/widgets/home_folder.dart b/lib/widgets/home_folder.dart
index 55e2be8..fdc0eba 100644
--- a/lib/widgets/home_folder.dart
+++ b/lib/widgets/home_folder.dart
@@ -77,7 +77,17 @@ class HomeFolder extends StatelessWidget {
if (badge != null) ...[const SizedBox(width: 7), badge!],
]),
const Spacer(),
- Text(detail,
+ Text.rich(
+ TextSpan(children: [
+ for (final (i, part) in detail.split('☆').indexed) ...[
+ if (i > 0)
+ WidgetSpan(
+ alignment: PlaceholderAlignment.middle,
+ child: Icon(PhosphorIconsRegular.star, size: 11, color: gc.textSecondary),
+ ),
+ TextSpan(text: part),
+ ],
+ ]),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: AppTheme.f(11, weight: FontWeight.w600, color: gc.textSecondary)),