Skip to content

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

Browse exercises by muscle with body cards

InlitXede155b59b59
diff --git a/lib/screens/exercises_screen.dart b/lib/screens/exercises_screen.dart
index 017c05d..9b0fa13 100644
--- a/lib/screens/exercises_screen.dart
+++ b/lib/screens/exercises_screen.dart
@@ -13,6 +13,7 @@ import '../services/media_store.dart';
import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
+import '../widgets/body_map.dart';
import '../widgets/exercise_media.dart';
import '../widgets/glass.dart';
import '../widgets/svg_icon.dart';
@@ -186,6 +187,20 @@ class _ExercisesScreenState extends State<ExercisesScreen> {
scrollDirection: Axis.horizontal,
clipBehavior: Clip.none,
child: Row(children: [
+ Pill(
+ label: fit.exZoneFilter != null
+ ? t.muscleGroupName(fit.exZoneFilter!)
+ : fit.exMuscleFilter != null
+ ? muscleLabel(fit.exMuscleFilter!)
+ : t.byZone,
+ bg: fit.exZoneFilter == null && fit.exMuscleFilter == null ? gc.bgRaised2 : gc.ember,
+ fg: fit.exZoneFilter == null && fit.exMuscleFilter == null ? gc.textSecondary : gc.onEmber,
+ onTap: () => showBodyZones(context),
+ hPad: 14,
+ vPad: 7,
+ fontSize: 12.5,
+ ),
+ const SizedBox(width: 8),
Pill(
label: active > 0 ? '${t.filters} · $active' : t.filters,
bg: active > 0 ? gc.ember : gc.bgRaised2,
@@ -916,3 +931,159 @@ Widget _chipRow(List<_FilterChipData> chips, GymColors gc,
]),
);
}
+
+Future<void> showBodyZones(BuildContext context) => showAppSheet<void>(
+ context: context,
+ backgroundColor: Colors.transparent,
+ isScrollControlled: true,
+ builder: (sheet) {
+ final gc = sheet.gc;
+ void pick(VoidCallback apply) {
+ HapticFeedback.selectionClick();
+ apply();
+ Navigator.of(sheet).pop();
+ }
+
+ return Container(
+ padding: sheetPad(sheet),
+ constraints: BoxConstraints(maxHeight: MediaQuery.sizeOf(sheet).height * 0.9),
+ decoration: BoxDecoration(
+ color: gc.bgRaised,
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
+ ),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SheetHandle(),
+ const SizedBox(height: 18),
+ Text(t.byZone, style: AppTheme.f(19, weight: FontWeight.w800, color: gc.text)),
+ const SizedBox(height: 6),
+ Flexible(
+ child: SingleChildScrollView(
+ child: LayoutBuilder(builder: (context, box) {
+ final w = (box.maxWidth - 16) / 3;
+ final singles = [for (final z in kBodyZones.values) if (z.length == 1) z.single];
+ Widget card(String m) => SizedBox(
+ width: w,
+ child: _ZoneCard(
+ muscles: [m],
+ label: muscleLabel(m),
+ selected: fit.exMuscleFilter == m,
+ onTap: () => pick(() => fit.setMuscleFilter(m)),
+ ),
+ );
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ const SizedBox(height: 12),
+ Wrap(spacing: 8, runSpacing: 8, children: [for (final m in singles) card(m)]),
+ for (final zone in kBodyZones.entries)
+ if (zone.value.length > 1) ...[
+ _ZoneHeader(
+ zone: zone.key,
+ selected: fit.exZoneFilter == zone.key,
+ onTap: () => pick(() => fit.setZoneFilter(fit.exZoneFilter == zone.key ? null : zone.key)),
+ ),
+ Wrap(spacing: 8, runSpacing: 8, children: [for (final m in zone.value) card(m)]),
+ ],
+ const SizedBox(height: 6),
+ ],
+ );
+ }),
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ );
+
+class _ZoneHeader extends StatelessWidget {
+ const _ZoneHeader({required this.zone, required this.selected, this.onTap});
+
+ final String zone;
+ final bool selected;
+ final VoidCallback? onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(2, 18, 2, 10),
+ child: Row(children: [
+ Expanded(
+ child: Text(t.muscleGroupName(zone).toUpperCase(),
+ style: AppTheme.f(11, weight: FontWeight.w700, color: gc.textSecondary, letterSpacing: 1.3)),
+ ),
+ if (onTap != null)
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
+ decoration: BoxDecoration(
+ color: selected ? gc.ember : gc.bgRaised2,
+ borderRadius: BorderRadius.circular(100),
+ ),
+ child: Text('${t.allExercisesShort} · ${fit.zoneCount(zone)}',
+ style: AppTheme.f(11.5, weight: FontWeight.w700, color: selected ? gc.onEmber : gc.textSecondary)),
+ ),
+ ]),
+ ),
+ );
+ }
+}
+
+class _ZoneCard extends StatelessWidget {
+ const _ZoneCard({required this.muscles, required this.label, required this.selected, required this.onTap});
+
+ final List<String> muscles;
+ final String label;
+ final bool selected;
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ return Semantics(
+ button: true,
+ selected: selected,
+ label: label,
+ excludeSemantics: true,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: AnimatedContainer(
+ duration: const Duration(milliseconds: 180),
+ padding: const EdgeInsets.fromLTRB(10, 12, 10, 10),
+ decoration: BoxDecoration(
+ color: gc.bgRaised2,
+ borderRadius: BorderRadius.circular(18),
+ border: Border.all(color: selected ? gc.text : Colors.transparent, width: 1.5),
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ height: 92,
+ width: double.infinity,
+ child: FittedBox(child: BodyZoneArt(muscles: muscles, height: 92)),
+ ),
+ const SizedBox(height: 10),
+ Text(label,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(13, weight: FontWeight.w700, color: gc.text)),
+ const SizedBox(height: 1),
+ Text(t.exerciseCount(fit.musclesCount(muscles)),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: AppTheme.f(11, weight: FontWeight.w500, color: gc.textSecondary)),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/state/library_state.dart b/lib/state/library_state.dart
index ea6afb2..1124b18 100644
--- a/lib/state/library_state.dart
+++ b/lib/state/library_state.dart
@@ -3,6 +3,7 @@ part of 'fit_state.dart';
mixin LibraryState on FitCore {
String exSearch = '';
String? exMuscleFilter;
+ String? exZoneFilter;
String? exDifficultyFilter;
String? exEquipmentFilter;
String? exKindFilter;
@@ -95,6 +96,7 @@ mixin LibraryState on FitCore {
void clearExFilters() {
exSearch = '';
exMuscleFilter = null;
+ exZoneFilter = null;
exDifficultyFilter = null;
exEquipmentFilter = null;
exKindFilter = null;
@@ -105,9 +107,21 @@ mixin LibraryState on FitCore {
void setMuscleFilter(String id) {
exMuscleFilter = exMuscleFilter == id ? null : id;
+ exZoneFilter = null;
notifyListeners();
}
+ void setZoneFilter(String? zone) {
+ exZoneFilter = zone;
+ exMuscleFilter = null;
+ notifyListeners();
+ }
+
+ int zoneCount(String zone) => musclesCount(kBodyZones[zone] ?? const []);
+
+ int musclesCount(List<String> muscles) =>
+ allExercises.where((ex) => !isArchived(ex.id) && muscles.contains(ex.primary)).length;
+
void setDifficultyFilter(String d) {
exDifficultyFilter = exDifficultyFilter == d ? null : d;
notifyListeners();
@@ -152,11 +166,18 @@ mixin LibraryState on FitCore {
!ex.secondary.contains(exMuscleFilter)) {
return false;
}
+ final zone = kBodyZones[exZoneFilter];
+ if (zone != null && !zone.contains(ex.primary) && !ex.secondary.any(zone.contains)) return false;
if (exDifficultyFilter != null && ex.difficulty != exDifficultyFilter) return false;
if (exEquipmentFilter != null && ex.equipment != exEquipmentFilter) return false;
if (exKindFilter != null && kindOf(ex) != exKindFilter) return false;
return true;
}).toList();
+ final zone = kBodyZones[exZoneFilter];
+ if (zone != null) {
+ final inside = _groupedByMuscle(list.where((ex) => zone.contains(ex.primary)).toList());
+ return [...inside, ..._groupedByMuscle(list.where((ex) => !zone.contains(ex.primary)).toList())];
+ }
final muscle = exMuscleFilter;
if (muscle == null) return _groupedByMuscle(list);
final primary = list.where((ex) => ex.primary == muscle);
@@ -319,7 +340,7 @@ mixin LibraryState on FitCore {
final from = s.exercises[i];
final j = s.exercises.indexWhere((e) => e.id == toId);
if (j < 0) {
- s.exercises[i] = LoggedExercise(to.id, to.name, to.primary, from.sets);
+ s.exercises[i] = LoggedExercise(to.id, to.name, to.primary, from.sets, incline: from.incline, kcal: from.kcal);
} else {
s.exercises[j].sets.addAll(from.sets);
s.exercises.removeAt(i);
diff --git a/lib/widgets/body_map.dart b/lib/widgets/body_map.dart
index 217f4c8..9e7939c 100644
--- a/lib/widgets/body_map.dart
+++ b/lib/widgets/body_map.dart
@@ -175,16 +175,20 @@ class _BodyCanvas extends StatelessWidget {
}
class BodyPainter extends CustomPainter {
- BodyPainter({required this.gc, required this.color, required this.token, this.outline});
+ BodyPainter({required this.gc, required this.color, required this.token, this.outline, this.crop});
final GymColors gc;
final Color Function(String id) color;
final String token;
final String? outline;
+ final Rect? crop;
@override
void paint(Canvas canvas, Size size) {
- canvas.scale(size.width / bodyViewW);
+ final view = crop ?? const Rect.fromLTWH(0, 0, bodyViewW, bodyViewH);
+ canvas.clipRect(Offset.zero & size);
+ canvas.scale(size.width / view.width);
+ canvas.translate(-view.left, -view.top);
final bodyMain = gc.bgRaised2;
final bodyLite = Color.lerp(gc.bgRaised2, gc.textTertiary, 0.14)!;
@@ -220,7 +224,7 @@ class BodyPainter extends CustomPainter {
@override
bool shouldRepaint(BodyPainter old) =>
- old.gc != gc || old.token != token || old.outline != outline;
+ old.gc != gc || old.token != token || old.outline != outline || old.crop != crop;
}
Color untrainedColor(GymColors gc, int? days) {
@@ -253,3 +257,46 @@ class BodyUntrainedMap extends StatelessWidget {
);
}
}
+
+final Map<String, Rect> _zoneViews = {};
+
+Rect bodyViewFor(List<String> muscles) => _zoneViews.putIfAbsent(muscles.join(','), () {
+ const half = bodyViewW / 2;
+ var front = false, back = false;
+ for (final id in muscles) {
+ for (final d in muscleFills[id] ?? const <String>[]) {
+ if (svgPath(d).getBounds().center.dx < half) {
+ front = true;
+ } else {
+ back = true;
+ }
+ }
+ }
+ if (front == back) return const Rect.fromLTWH(0, 0, bodyViewW, bodyViewH);
+ return Rect.fromLTWH(front ? 0 : half, 0, half, bodyViewH);
+ });
+
+class BodyZoneArt extends StatelessWidget {
+ const BodyZoneArt({super.key, required this.muscles, required this.height, this.color});
+
+ final List<String> muscles;
+ final double height;
+ final Color? color;
+
+ @override
+ Widget build(BuildContext context) {
+ final gc = context.gc;
+ final view = bodyViewFor(muscles);
+ final idle = idleMuscle(gc);
+ final on = color ?? heatRamp(gc, fit.heatTone)[2];
+ return CustomPaint(
+ size: Size(height * view.width / view.height, height),
+ painter: BodyPainter(
+ gc: gc,
+ token: 'z${muscles.join(',')}$on',
+ crop: view,
+ color: (id) => muscles.contains(id) ? on : idle,
+ ),
+ );
+ }
+}