Skip to content

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

Support rep ranges in routines

InlitXd09c7e2c83a8
diff --git a/lib/models/workout.dart b/lib/models/workout.dart
index 99fb914..ee2dc78 100644
--- a/lib/models/workout.dart
+++ b/lib/models/workout.dart
@@ -175,8 +175,11 @@ class BodyweightEntry {
}
class PlannedSet {
- const PlannedSet({this.reps, this.weightKg, this.kind = SetKind.normal, this.sec, this.km});
+ const PlannedSet({this.reps, this.repsMax, this.weightKg, this.kind = SetKind.normal, this.sec, this.km});
final int? reps;
+ final int? repsMax;
+
+ String? get repsLabel => reps == null ? null : (repsMax != null && repsMax! > reps! ? '$reps-$repsMax' : '$reps');
final double? weightKg;
final SetKind kind;
final int? sec;
@@ -184,6 +187,8 @@ class PlannedSet {
PlannedSet copyWith({
int? reps,
+ int? repsMax,
+ bool clearRange = false,
double? weightKg,
SetKind? kind,
int? sec,
@@ -192,6 +197,7 @@ class PlannedSet {
}) =>
PlannedSet(
reps: reps ?? this.reps,
+ repsMax: clearRange ? null : (repsMax ?? this.repsMax),
weightKg: autoWeight ? null : (weightKg ?? this.weightKg),
kind: kind ?? this.kind,
sec: sec ?? this.sec,
@@ -200,6 +206,7 @@ class PlannedSet {
Map<String, dynamic> toJson() => {
if (reps != null) 'r': reps,
+ if (repsMax != null) 'rm': repsMax,
if (weightKg != null) 'w': weightKg,
if (kind != SetKind.normal) 'k': kind.index,
if (sec != null) 't': sec,
@@ -207,6 +214,7 @@ class PlannedSet {
};
factory PlannedSet.fromJson(Map<String, dynamic> j) => PlannedSet(
reps: (j['r'] as num?)?.toInt(),
+ repsMax: (j['rm'] as num?)?.toInt(),
weightKg: (j['w'] as num?)?.toDouble(),
kind: setKindFrom(j['k']),
sec: (j['t'] as num?)?.toInt(),
diff --git a/lib/screens/exercises_screen.dart b/lib/screens/exercises_screen.dart
index 9573e83..c10c68f 100644
--- a/lib/screens/exercises_screen.dart
+++ b/lib/screens/exercises_screen.dart
@@ -14,6 +14,7 @@ import '../state/fit_state.dart';
import '../theme/app_colors.dart';
import '../theme/app_theme.dart';
import '../widgets/body_map.dart';
+import '../widgets/dialogs.dart';
import '../widgets/exercise_media.dart';
import '../widgets/glass.dart';
import '../widgets/svg_icon.dart';
@@ -726,7 +727,7 @@ void showCreateExerciseSheet(BuildContext context,
const SizedBox(height: 10),
Builder(builder: (_) {
const common = ['Bodyweight', 'Dumbbell', 'Barbell', 'Machine', 'Cable', 'Band'];
- final rest = [for (final e in kEquipment) if (!common.contains(e)) e];
+ final rest = [for (final e in [...kEquipment, ...fit.customGear]) if (!common.contains(e)) e];
final all = allEquipment || rest.contains(equipment);
return Wrap(spacing: 8, runSpacing: 8, children: [
for (final e in [...common, if (all) ...rest])
@@ -742,6 +743,23 @@ void showCreateExerciseSheet(BuildContext context,
vPad: 8,
fontSize: 13,
),
+ Pill(
+ label: t.equipNew,
+ bg: Colors.transparent,
+ fg: gc.accent,
+ onTap: () async {
+ final name = await askText(context, title: t.equipNewTitle, hint: t.equipNewHint);
+ if (name == null || name.trim().isEmpty) return;
+ final added = fit.addCustomGear(name);
+ setSheet(() {
+ equipment = added;
+ allEquipment = true;
+ });
+ },
+ hPad: 12,
+ vPad: 8,
+ fontSize: 13,
+ ),
if (!all)
Pill(
label: '+${rest.length}',
diff --git a/lib/screens/routine_edit_screen.dart b/lib/screens/routine_edit_screen.dart
index b20ffb0..5e4a9c7 100644
--- a/lib/screens/routine_edit_screen.dart
+++ b/lib/screens/routine_edit_screen.dart
@@ -464,7 +464,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
final load = [
if (p.km != null) fit.distanceValue(p.km!),
if (p.sec != null) durationLabel(p.sec!),
- if (p.reps != null) '${p.reps}',
+ if (p.reps != null) p.repsLabel!,
if (p.weightKg != null) fit.weightValue(p.weightKg!),
].join(' × ');
final tag = setKindTag(p.kind);
@@ -1134,7 +1134,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
) {
final p = plan[i];
final auto = t.autoValue;
- Widget cell(String value, VoidCallback dec, VoidCallback inc, VoidCallback onEdit) => Expanded(
+ Widget cell(String value, VoidCallback dec, VoidCallback inc, VoidCallback onEdit, {VoidCallback? onLongPress}) => Expanded(
child: FittedBox(
fit: BoxFit.scaleDown,
child: StepperControl(
@@ -1147,6 +1147,7 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
onDec: dec,
onInc: inc,
onEdit: onEdit,
+ onLongPress: onLongPress,
),
),
);
@@ -1185,12 +1186,50 @@ class _RoutineEditScreenState extends State<RoutineEditScreen> {
fit.units,
(v) => edit(i, v <= 0 ? p.copyWith(autoWeight: true) : p.copyWith(weightKg: fit.fromDisplayWeight(v)))),
);
+ void shiftReps(int by) {
+ final from = p.reps ?? 10;
+ final next = (from + by).clamp(1, 999);
+ final max = p.repsMax;
+ edit(i, p.copyWith(reps: next, repsMax: max == null ? null : (max + next - from).clamp(next, 999)));
+ }
+
final reps = cell(
- p.reps == null ? auto : '${p.reps}',
- () => edit(i, p.copyWith(reps: ((p.reps ?? 10) - 1).clamp(1, 999))),
- () => edit(i, p.copyWith(reps: ((p.reps ?? 10) + 1).clamp(1, 999))),
- () => ask(t.repsTitle, (p.reps ?? 10).toDouble(), 100, 1, 5, '',
- (v) => edit(i, p.copyWith(reps: v.round().clamp(1, 999)))),
+ p.reps == null ? auto : p.repsLabel!,
+ () => shiftReps(-1),
+ () => shiftReps(1),
+ () async {
+ final v = await askRuler(sheet,
+ title: t.repsTitle,
+ value: (p.reps ?? 10).toDouble(),
+ min: 0,
+ max: 100,
+ step: 1,
+ majorEvery: 5,
+ hint: t.repsRangeHint);
+ if (v == null) return;
+ final next = v.round().clamp(1, 999);
+ final max = p.repsMax;
+ edit(i, p.copyWith(reps: next, clearRange: max != null && max <= next));
+ },
+ onLongPress: () async {
+ final low = p.reps ?? 10;
+ final v = await askRuler(sheet,
+ title: t.repsMaxTitle,
+ value: (p.repsMax ?? low).toDouble(),
+ min: low.toDouble(),
+ max: 100,
+ step: 1,
+ unit: '',
+ majorEvery: 5,
+ clearLabel: p.repsMax == null ? null : t.repsRangeClear);
+ if (v == null) return;
+ if (v.isNaN) {
+ edit(i, p.copyWith(clearRange: true));
+ return;
+ }
+ final max = v.round();
+ edit(i, max > low ? p.copyWith(reps: low, repsMax: max) : p.copyWith(reps: low, clearRange: true));
+ },
);
final cardio = mode == 'cardio';
final step = cardio ? 60 : 15;
diff --git a/lib/screens/session_screen.dart b/lib/screens/session_screen.dart
index a147d80..85d4aa6 100644
--- a/lib/screens/session_screen.dart
+++ b/lib/screens/session_screen.dart
@@ -1461,7 +1461,7 @@ class SessionScreen extends StatelessWidget {
context,
title: t.timeSecondsTitle,
value: (st.sec ?? 0).toDouble(),
- max: 900,
+ max: 3600,
step: 5,
majorEvery: 6,
format: (v) => clockLabel(v.round()),
diff --git a/test/custom_exercises_test.dart b/test/custom_exercises_test.dart
index e685bf5..5c590a1 100644
--- a/test/custom_exercises_test.dart
+++ b/test/custom_exercises_test.dart
@@ -147,6 +147,15 @@ void main() {
expect(fit.exercisesMatching('bulgara').map((e) => e.id), contains(id));
});
+ test('el material propio se guarda una vez y no se repite', () {
+ expect(fit.addCustomGear(' Cinturón de lastre '), 'Cinturón de lastre');
+ expect(fit.addCustomGear('cinturón de lastre'), 'Cinturón de lastre');
+ expect(fit.addCustomGear('barbell'), 'Barbell');
+ expect(fit.customGear, ['Cinturón de lastre']);
+ final id = fit.addCustomExercise(name: 'Dominada lastrada', primary: 'lats', equipment: 'Cinturón de lastre');
+ expect(fit.exerciseById(id)!.equipment, 'Cinturón de lastre');
+ });
+
test('el selector de la rutina respeta los filtros de la biblioteca', () {
fit.setEquipmentFilter('Bodyweight');
expect(fit.exercisesMatching('').every((e) => e.equipment == 'Bodyweight'), isTrue);