Skip to content

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

Tag several foods as shakes

InlitX18c7100e338b
diff --git a/lib/screens/nutrition/cards.dart b/lib/screens/nutrition/cards.dart
index c3b90cc..536ab92 100644
--- a/lib/screens/nutrition/cards.dart
+++ b/lib/screens/nutrition/cards.dart
@@ -794,29 +794,73 @@ class _ShakeTile extends StatelessWidget {
}
Future<void> showShakePicker(BuildContext context) => _sheet<void>(context, (context) {
- final foods = fit.foodsByUse;
+ final gc = context.gc;
+ final shakes = fit.shakeFoodItems;
+ final others = [for (final f in fit.foodsByUse) if (!fit.isShakeFood(f.id)) f];
return _sheetFrame(context, [
SheetTitle(t.shakePick, subtitle: t.shakePickHint),
const SizedBox(height: 16),
- if (foods.isNotEmpty) ...[
+ if (shakes.isNotEmpty)
OptionGroup([
- for (final f in foods)
+ for (final f in shakes)
OptionItem(
f.name,
leading: FoodSticker(photo: f.photo, name: f.name, size: 32, tilt: false),
detail: '${_g(f.macros.protein)} g',
selected: f.id == fit.shakeFoodId,
+ trailing: Semantics(
+ button: true,
+ label: t.shakeUntag,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ HapticFeedback.selectionClick();
+ fit.setShakeTag(f.id, false);
+ },
+ child: SizedBox(
+ width: 34,
+ height: 34,
+ child: Icon(PhosphorIconsBold.x, size: 14, color: gc.textTertiary),
+ ),
+ ),
+ ),
onTap: () {
fit.setShakeFood(f.id);
Navigator.of(context).pop();
},
),
- ]),
- const SizedBox(height: 12),
+ ])
+ else
+ Container(
+ padding: const EdgeInsets.fromLTRB(14, 14, 16, 14),
+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(18)),
+ child: Row(children: [
+ Image.asset('assets/img/peek-shake.webp', width: 34, height: 40, fit: BoxFit.contain),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text(t.shakeNone, style: AppTheme.f(13, weight: FontWeight.w600, color: gc.textSecondary, height: 1.35)),
+ ),
+ ]),
+ ),
+ if (others.isNotEmpty) ...[
+ const SizedBox(height: 18),
+ Text(t.shakeMarkLabel,
+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.1)),
+ const SizedBox(height: 8),
+ SizedBox(
+ height: 44,
+ child: ListView.separated(
+ scrollDirection: Axis.horizontal,
+ itemCount: others.length,
+ separatorBuilder: (_, _) => const SizedBox(width: 8),
+ itemBuilder: (_, i) => _ShakeChip(others[i]),
+ ),
+ ),
],
+ const SizedBox(height: 16),
GhostButton(
- label: t.newFood,
- icon: PhosphorIconsBold.camera,
+ label: t.shakeNew,
+ icon: PhosphorIconsBold.plus,
onTap: () {
Navigator.of(context).pop();
showFoodEditor(context, asShake: true);
@@ -825,6 +869,45 @@ Future<void> showShakePicker(BuildContext context) => _sheet<void>(context, (con
]);
});
+class _ShakeChip extends StatelessWidget {
+ const _ShakeChip(this.food);
+
+ final FoodItem food;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Pressable(
+ onTap: () {
+ HapticFeedback.selectionClick();
+ fit.setShakeTag(food.id, true);
+ },
+ scale: 0.95,
+ child: Container(
+ padding: const EdgeInsets.fromLTRB(6, 6, 12, 6),
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(100),
+ border: Border.all(color: gc.border),
+ ),
+ child: Row(mainAxisSize: MainAxisSize.min, children: [
+ FoodSticker(photo: food.photo, name: food.name, size: 30, tilt: false, shadow: false),
+ const SizedBox(width: 8),
+ ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 140),
+ child: Text(food.name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(13, weight: FontWeight.w700, color: gc.text)),
+ ),
+ const SizedBox(width: 6),
+ Icon(PhosphorIconsBold.plus, size: 13, color: gc.protein),
+ ]),
+ ),
+ );
+ }
+}
+
const _suppPresets = [
'asset:assets/img/peek-protein.webp',
'asset:assets/img/peek-shake.webp',
diff --git a/lib/screens/nutrition/food.dart b/lib/screens/nutrition/food.dart
index 5d24db5..0732362 100644
--- a/lib/screens/nutrition/food.dart
+++ b/lib/screens/nutrition/food.dart
@@ -1667,6 +1667,7 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
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 bool _shake = widget.asShake || (widget.food != null && fit.isShakeFood(widget.food!.id));
late final _p = TextEditingController(text: _seed(_base?.macros.protein ?? 0));
late final _c = TextEditingController(text: _seed(_base?.macros.carbs ?? 0));
late final _f = TextEditingController(text: _seed(_base?.macros.fat ?? 0));
@@ -1705,6 +1706,7 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
cookedYield: _base?.cookedYield ?? 0,
macros: _keepDetail(_macrosOf(_kcal, _p, _c, _f, fiber: _fi, sugar: _su, sodium: _na)),
);
+ fit.setShakeTag(saved.id, _shake);
if (widget.asShake) fit.setShakeFood(saved.id);
_dropDrafts(keep: _photo);
_photo = widget.food?.photo ?? '';
@@ -1836,6 +1838,8 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
child: Text(t.moreNutrients, style: AppTheme.f(12.5, weight: FontWeight.w700, color: gc.accent)),
),
),
+ const SizedBox(height: 10),
+ _ShakeToggle(on: _shake, onTap: () => setState(() => _shake = !_shake)),
const SizedBox(height: 18),
PrimaryButton(label: t.save, onTap: _working ? () {} : _save),
if (widget.food != null) ...[
@@ -1850,3 +1854,48 @@ class _FoodEditorState extends State<_FoodEditor> with _StickerDrafts {
]);
}
}
+
+class _ShakeToggle extends StatelessWidget {
+ const _ShakeToggle({required this.on, required this.onTap});
+
+ final bool on;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Semantics(
+ toggled: on,
+ button: true,
+ child: Pressable(
+ onTap: () {
+ HapticFeedback.selectionClick();
+ onTap();
+ },
+ scale: 0.98,
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 180),
+ padding: const EdgeInsets.fromLTRB(12, 10, 14, 10),
+ decoration: BoxDecoration(
+ color: on ? gc.protein.withValues(alpha: 0.1) : gc.bgRaised2,
+ borderRadius: BorderRadius.circular(18),
+ border: Border.all(color: on ? gc.protein.withValues(alpha: 0.45) : gc.border),
+ ),
+ child: Row(children: [
+ Image.asset('assets/img/peek-shake.webp', width: 30, height: 36, fit: BoxFit.contain),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(t.shakeTag, style: AppTheme.f(14, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(height: 2),
+ Text(t.shakeTagHint, style: AppTheme.f(12, weight: FontWeight.w500, color: gc.textSecondary)),
+ ]),
+ ),
+ const SizedBox(width: 10),
+ TinySwitch(on: on),
+ ]),
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/state/nutrition_state.dart b/lib/state/nutrition_state.dart
index 106d256..1908f0b 100644
--- a/lib/state/nutrition_state.dart
+++ b/lib/state/nutrition_state.dart
@@ -23,6 +23,7 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
double weightGoalKg = 0;
int? supplementReminderMin;
String shakeFoodId = '';
+ final List<String> shakeFoods = [];
DateTime nutritionDay = _dayKey(DateTime.now());
int _foodSeq = 0;
@@ -1073,6 +1074,27 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
void setShakeFood(String id) {
shakeFoodId = foodById(id) == null ? '' : id;
+ if (shakeFoodId.isNotEmpty && !shakeFoods.contains(id)) shakeFoods.add(id);
+ _persist();
+ notifyListeners();
+ }
+
+ bool isShakeFood(String id) => shakeFoods.contains(id);
+
+ List<FoodItem> get shakeFoodItems => [for (final f in foodsByUse) if (shakeFoods.contains(f.id)) f];
+
+ void setShakeTag(String id, bool on) {
+ if (on) {
+ if (foodById(id) == null || shakeFoods.contains(id)) return;
+ shakeFoods.add(id);
+ if (shakeFood == null) shakeFoodId = id;
+ } else {
+ if (!shakeFoods.remove(id)) return;
+ if (shakeFoodId == id) {
+ final rest = shakeFoodItems;
+ shakeFoodId = rest.isEmpty ? '' : rest.first.id;
+ }
+ }
_persist();
notifyListeners();
}
@@ -1081,6 +1103,7 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
final i = foods.indexWhere((f) => f.id == id);
if (i < 0) return;
if (shakeFoodId == id) shakeFoodId = '';
+ shakeFoods.remove(id);
favoriteFoods.remove(id);
final gone = foods.removeAt(i);
if (gone.photo.isNotEmpty && !isAssetPhoto(gone.photo)) MediaStore.delete(gone.photo);
@@ -1285,6 +1308,7 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
'trkKnown': [for (final t in Tracker.values) t.name],
'trackers': [for (final t in Tracker.values) if (trackers.contains(t)) t.name],
if (shakeFoodId.isNotEmpty) 'shake': shakeFoodId,
+ 'shakes': shakeFoods,
};
void loadNutrition(Map<String, dynamic>? j, {Map<String, String>? restored}) {
@@ -1373,6 +1397,13 @@ mixin NutritionState on FitCore, ToolsState, StatsState {
}
final shake = j?['shake'] as String? ?? '';
shakeFoodId = foods.any((f) => f.id == shake) ? shake : '';
+ final tagged = j?['shakes'];
+ shakeFoods
+ ..clear()
+ ..addAll(tagged is List
+ ? {...tagged.whereType<String>().where((id) => foods.any((f) => f.id == id))}
+ : [if (shakeFoodId.isNotEmpty) shakeFoodId]);
+ if (!shakeFoods.contains(shakeFoodId)) shakeFoodId = shakeFoods.isEmpty ? '' : shakeFoods.first;
nutritionDay = _dayKey(DateTime.now());
syncSupplementReminder();
}
diff --git a/lib/widgets/ui_kit.dart b/lib/widgets/ui_kit.dart
index 5f0f0b5..4405ef8 100644
--- a/lib/widgets/ui_kit.dart
+++ b/lib/widgets/ui_kit.dart
@@ -276,6 +276,7 @@ class OptionItem {
this.detail,
this.selected = false,
this.danger = false,
+ this.trailing,
});
final String label;
@@ -285,6 +286,7 @@ class OptionItem {
final String? detail;
final bool selected;
final bool danger;
+ final Widget? trailing;
}
class OptionGroup extends StatelessWidget {
@@ -368,6 +370,10 @@ class _OptionRow extends StatelessWidget {
const SizedBox(width: 10),
Icon(PhosphorIconsFill.checkCircle, size: 18, color: gc.ember),
],
+ if (o.trailing != null) ...[
+ const SizedBox(width: 6),
+ o.trailing!,
+ ],
]),
),
),