Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add supersets, planned sets, RPE, auto-advance and the next-session suggestion (#12, #25, #27)
InlitX50759ac7f707
diff --git a/lib/models/live_session.dart b/lib/models/live_session.dartindex b89ff26..7ed9c43 100644--- a/lib/models/live_session.dart+++ b/lib/models/live_session.dart@@ -1,11 +1,12 @@import 'workout.dart';class SessionSet {- SessionSet(this.reps, this.weight, this.done, {this.kind = SetKind.normal});+ SessionSet(this.reps, this.weight, this.done, {this.kind = SetKind.normal, this.rpe});int reps;double weight;bool done;SetKind kind;+ double? rpe;bool get counts => kind != SetKind.warmup;@@ -14,33 +15,40 @@ class SessionSet {'w': weight,'d': done,if (kind != SetKind.normal) 'k': kind.index,+ if (rpe != null) 'e': rpe,};factory SessionSet.fromJson(Map<String, dynamic> j) => SessionSet((j['r'] as num).toInt(),(j['w'] as num).toDouble(),j['d'] as bool? ?? false,kind: setKindFrom(j['k']),+ rpe: (j['e'] as num?)?.toDouble(),);}class SessionExercise {- SessionExercise(this.id, this.name, this.primary, this.sets);+ SessionExercise(this.id, this.name, this.primary, this.sets, {this.linkedNext = false});final String id;final String name;final String primary;final List<SessionSet> sets;+ bool linkedNext;++ bool get hasUndone => sets.any((s) => !s.done);Map<String, dynamic> toJson() => {'id': id,'n': name,'p': primary,'s': sets.map((s) => s.toJson()).toList(),+ if (linkedNext) 'l': true,};factory SessionExercise.fromJson(Map<String, dynamic> j) => SessionExercise(j['id'] as String,j['n'] as String,j['p'] as String,(j['s'] as List).map((e) => SessionSet.fromJson((e as Map).cast<String, dynamic>())).toList(),+ linkedNext: j['l'] as bool? ?? false,);}@@ -50,17 +58,36 @@ class WorkoutSession {List<SessionExercise> exercises = [];int currentIndex = 0;bool complete = false;+ bool manual = false;DateTime? loggedAt;- int? restRemaining;+ DateTime? restEndsAt;+ int? restFrozen;int? summaryVolume;int? summarySets;int? summaryDuration;+ int? get restRemaining {+ final frozen = restFrozen;+ if (frozen != null) return frozen;+ final end = restEndsAt;+ if (end == null) return null;+ final left = end.difference(DateTime.now()).inMilliseconds;+ return left <= 0 ? null : (left / 1000).ceil();+ }++ void clearRest() {+ restEndsAt = null;+ restFrozen = null;+ }+Map<String, dynamic> toJson() => {'ex': exercises.map((e) => e.toJson()).toList(),'i': currentIndex,'c': complete,+ if (manual) 'm': true,'at': loggedAt?.toIso8601String(),+ if (restEndsAt != null) 're': restEndsAt!.toIso8601String(),+ if (restFrozen != null) 'rf': restFrozen,'sv': summaryVolume,'ss': summarySets,'sd': summaryDuration,@@ -71,7 +98,10 @@ class WorkoutSession {(j['ex'] as List).map((e) => SessionExercise.fromJson((e as Map).cast<String, dynamic>())).toList()..currentIndex = (j['i'] as num?)?.toInt() ?? 0..complete = j['c'] as bool? ?? false+ ..manual = j['m'] as bool? ?? false..loggedAt = DateTime.tryParse((j['at'] as String?) ?? '')+ ..restEndsAt = DateTime.tryParse((j['re'] as String?) ?? '')+ ..restFrozen = (j['rf'] as num?)?.toInt()..summaryVolume = (j['sv'] as num?)?.toInt()..summarySets = (j['ss'] as num?)?.toInt()..summaryDuration = (j['sd'] as num?)?.toInt();diff --git a/lib/models/workout.dart b/lib/models/workout.dartindex d577b6b..ea5610c 100644--- a/lib/models/workout.dart+++ b/lib/models/workout.dart@@ -6,10 +6,11 @@ SetKind setKindFrom(Object? raw) {}class LoggedSet {- LoggedSet(this.reps, this.weight, {this.kind = SetKind.normal});+ LoggedSet(this.reps, this.weight, {this.kind = SetKind.normal, this.rpe});final int reps;final double weight;final SetKind kind;+ final double? rpe;bool get counts => kind != SetKind.warmup;double get volume => reps * weight;@@ -20,11 +21,13 @@ class LoggedSet {'r': reps,'w': weight,if (kind != SetKind.normal) 'k': kind.index,+ if (rpe != null) 'e': rpe,};factory LoggedSet.fromJson(Map<String, dynamic> j) => LoggedSet((j['r'] as num).toInt(),(j['w'] as num).toDouble(),kind: setKindFrom(j['k']),+ rpe: (j['e'] as num?)?.toDouble(),);}@@ -94,15 +97,32 @@ class BodyweightEntry {}class Routine {- Routine(this.id, this.name, this.exerciseIds);+ Routine(this.id, this.name, this.exerciseIds,+ {Map<String, int>? sets, Set<String>? chained, this.group = ''})+ : sets = sets ?? {},+ chained = chained ?? {};final String id;String name;+ String group;final List<String> exerciseIds;+ final Map<String, int> sets;+ final Set<String> chained;- Map<String, dynamic> toJson() => {'id': id, 'n': name, 'ex': exerciseIds};+ Map<String, dynamic> toJson() => {+ 'id': id,+ 'n': name,+ 'ex': exerciseIds,+ if (sets.isNotEmpty) 's': sets,+ if (chained.isNotEmpty) 'c': chained.toList(),+ if (group.isNotEmpty) 'g': group,+ };factory Routine.fromJson(Map<String, dynamic> j) => Routine(j['id'] as String,j['n'] as String,((j['ex'] as List?) ?? []).cast<String>(),+ sets: ((j['s'] as Map?) ?? const {})+ .map((k, v) => MapEntry(k as String, (v as num).toInt())),+ chained: ((j['c'] as List?) ?? const []).cast<String>().toSet(),+ group: (j['g'] as String?) ?? '',);}diff --git a/lib/screens/session_screen.dart b/lib/screens/session_screen.dartindex 6fdcbfb..93bf9df 100644--- a/lib/screens/session_screen.dart+++ b/lib/screens/session_screen.dart@@ -1,7 +1,6 @@import 'package:flutter/material.dart';-import 'package:phosphor_flutter/phosphor_flutter.dart';+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';-import '../catalog/exercise_catalog.dart';import '../l10n/l10n.dart';import '../models/exercise.dart';import '../models/live_session.dart';@@ -15,6 +14,7 @@ import '../widgets/share_cards.dart';import '../widgets/svg_icon.dart';import '../widgets/ui_kit.dart';import 'exercises_screen.dart';+import 'tool_detail_screen.dart';import 'share_sheet.dart';class SessionScreen extends StatelessWidget {@@ -36,92 +36,54 @@ class SessionScreen extends StatelessWidget {final s = fit.session!;final ex = fit.currentExercise;final exIdx = s.currentIndex;- final def = fit.exerciseById(ex?.id ?? '') ?? kExercises.first;+ final def = fit.exerciseById(ex?.id ?? '') ?? fit.allExercises.first;final repsOnly = ex != null && fit.isRepsOnly(ex.id);return Column(crossAxisAlignment: CrossAxisAlignment.stretch,children: [- Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Row(children: [- Container(- width: 8,- height: 8,- decoration: BoxDecoration(- color: fit.sessionPaused ? gc.textTertiary : gc.ember, shape: BoxShape.circle),- ),- const SizedBox(width: 8),- Text(- fit.sessionPaused ? t.paused : t.inProgress,- style: AppTheme.d(12,- weight: FontWeight.w600,- color: fit.sessionPaused ? gc.textTertiary : gc.ember,- letterSpacing: 2),- ),- ]),- Row(children: [- Text(fit.elapsedLabel,- style: AppTheme.d(18,- weight: FontWeight.w700, color: fit.sessionPaused ? gc.textSecondary : gc.text)),- const SizedBox(width: 10),- Semantics(- button: true,- label: fit.sessionPaused ? t.resumeWorkout : t.pauseWorkout,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: fit.toggleSessionPause,- child: SizedBox(- width: 48,- height: 48,- child: Center(- child: Container(- width: 36,- height: 36,- decoration: BoxDecoration(- color: fit.sessionPaused ? gc.ember : gc.bgRaised2,- shape: BoxShape.circle,- border: Border.all(color: fit.sessionPaused ? gc.ember : gc.border),- ),- child: Icon(- fit.sessionPaused ? PhosphorIconsFill.play : PhosphorIconsFill.pause,- size: 16,- color: fit.sessionPaused ? gc.onEmber : gc.text,- ),- ),- ),- ),- ),- ),- ]),- ],- ),+ s.manual ? _manualBar(gc, s) : _liveBar(gc),const SizedBox(height: 18),Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- Text(fit.sessionProgressLabel,- style: AppTheme.s(12, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1)),+ Row(children: [+ Text(fit.sessionProgressLabel,+ style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4)),+ if (fit.inSuperset) ...[+ const SizedBox(width: 8),+ Container(+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),+ decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(100)),+ child: Row(mainAxisSize: MainAxisSize.min, children: [+ Icon(PhosphorIconsRegular.link, size: 11, color: gc.brass),+ const SizedBox(width: 5),+ Text(t.superset,+ style: AppTheme.f(10.5, weight: FontWeight.w700, color: gc.brass, letterSpacing: 0.5)),+ ]),+ ),+ ],+ ]),const SizedBox(height: 4),- Text(ex == null ? '' : t.catalogName(ex.id, ex.name), style: AppTheme.d(26, weight: FontWeight.w700, color: gc.text)),+ Text(ex == null ? '' : t.catalogName(ex.id, ex.name), style: AppTheme.f(26, weight: FontWeight.w700, color: gc.text)),const SizedBox(height: 8),Container(padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),decoration: BoxDecoration(color: gc.emberSoft, borderRadius: BorderRadius.circular(100)),child: Text(muscleLabel(ex?.primary ?? ''),- style: AppTheme.s(12, weight: FontWeight.w600, color: gc.ember)),+ style: AppTheme.f(12, weight: FontWeight.w600, color: gc.ember)),),if (ex != null && fit.lastSummaryFor(ex.id) != null) ...[const SizedBox(height: 10),Row(children: [Text(t.last,- style: AppTheme.s(11, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 1)),+ style: AppTheme.f(11, weight: FontWeight.w600, color: gc.textTertiary, letterSpacing: 0.4)),const SizedBox(width: 8),Expanded(child: Text(fit.lastSummaryFor(ex.id)!,- style: AppTheme.s(12, weight: FontWeight.w600, color: gc.textSecondary)),+ style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textSecondary)),),]),+ if (fit.nextTargetLabel(ex.id) != null) _nextRow(gc, ex.id),],],),@@ -130,43 +92,50 @@ class SessionScreen extends StatelessWidget {const SizedBox(height: 18),if (s.restRemaining != null) ...[Container(- padding: const EdgeInsets.all(20),+ padding: const EdgeInsets.fromLTRB(10, 10, 12, 10),decoration: BoxDecoration(color: gc.bgRaised,- border: Border.all(color: gc.ember),- borderRadius: BorderRadius.circular(20),+ borderRadius: BorderRadius.circular(22),),- child: Column(children: [- Text(t.rest, style: AppTheme.s(12, weight: FontWeight.w600, color: gc.brass, letterSpacing: 2)),- const SizedBox(height: 6),- Row(mainAxisAlignment: MainAxisAlignment.center, children: [+ child: Row(+ children: [_restNudge(gc, '−15', t.decrease, () => fit.nudgeRest(-15)),- const SizedBox(width: 14),- Text('${s.restRemaining}s', style: AppTheme.d(48, weight: FontWeight.w700, color: gc.text)),- const SizedBox(width: 14),+ Expanded(+ child: Column(+ children: [+ Text(t.rest.toUpperCase(),+ style: AppTheme.f(9.5,+ weight: FontWeight.w700,+ color: gc.textTertiary,+ letterSpacing: 1.5)),+ const SizedBox(height: 3),+ Text('${s.restRemaining}s',+ style: AppTheme.f(30, weight: FontWeight.w800, color: gc.text)),+ ],+ ),+ ),_restNudge(gc, '+15', t.increase, () => fit.nudgeRest(15)),- ]),- const SizedBox(height: 4),- Text(t.restDefault(fit.restSeconds), style: AppTheme.s(11, color: gc.textTertiary)),- const SizedBox(height: 8),- GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: fit.skipRest,- child: Container(- padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),- decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(100)),- child: Text(t.skip, style: AppTheme.s(13, weight: FontWeight.w600, color: gc.text, letterSpacing: 1)),+ const SizedBox(width: 4),+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: fit.skipRest,+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 11),+ decoration:+ BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(100)),+ child: Text(titleCase(t.skip),+ style: AppTheme.f(12.5, weight: FontWeight.w700, color: gc.text)),+ ),),- ),- ]),+ ],+ ),),- const SizedBox(height: 18),+ const SizedBox(height: 16),],Container(padding: const EdgeInsets.fromLTRB(_cardPad, 16, _cardPad, 16),decoration: BoxDecoration(color: gc.bgRaised,- border: Border.all(color: gc.border),borderRadius: BorderRadius.circular(20),),child: Column(@@ -177,7 +146,7 @@ class SessionScreen extends StatelessWidget {),for (int j = 0; j < (ex?.sets.length ?? 0); j++)_setRow(gc, exIdx, j, ex!.sets[j], repsOnly),- if (!repsOnly && ex != null) _plateRow(gc, ex),+ if (!repsOnly && ex != null) _plateRow(context, gc, ex),const SizedBox(height: 10),Padding(padding: const EdgeInsets.symmetric(horizontal: _rowPad),@@ -196,7 +165,7 @@ class SessionScreen extends StatelessWidget {],),),- const SizedBox(height: 12),+ const SizedBox(height: 22),Row(children: [Expanded(@@ -218,7 +187,6 @@ class SessionScreen extends StatelessWidget {height: 46,alignment: Alignment.center,decoration: BoxDecoration(- border: Border.all(color: gc.border),borderRadius: BorderRadius.circular(14),),child: Icon(PhosphorIconsRegular.notePencil, size: 17, color: gc.ember),@@ -227,34 +195,58 @@ class SessionScreen extends StatelessWidget {),],),- const SizedBox(height: 6),- if (ex != null && s.exercises.length > 1)- Center(- child: Semantics(- button: true,- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () => _confirmDrop(context, exIdx, t.catalogName(ex.id, ex.name)),- child: Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),- child: Text(t.dropExercise,- style: AppTheme.s(12, weight: FontWeight.w600, color: gc.textTertiary)),- ),- ),- ),- ),- const SizedBox(height: 6),+ const SizedBox(height: 16),Row(children: [- _circleBtn(gc, Ic.chevronLeft, fit.prevExercise),+ _circleBtn(gc, Ic.chevronLeft, fit.prevExercise, enabled: exIdx > 0),const SizedBox(width: 10),- Expanded(child: PrimaryButton(label: t.finishSession, onTap: fit.finishSession, height: 56)),+ Expanded(child: _mainAction(gc, ex, exIdx, s.exercises.length)),const SizedBox(width: 10),- _circleBtn(gc, Ic.chevronRightBold, fit.nextExercise),+ _circleBtn(gc, Ic.chevronRightBold, () => _goNext(context, ex),+ enabled: exIdx < s.exercises.length - 1),+ ]),+ const SizedBox(height: 10),+ Row(mainAxisAlignment: MainAxisAlignment.center, children: [+ if (ex != null && s.exercises.length > 1) ...[+ _textAction(gc, t.dropExerciseAction,+ () => _confirmDrop(context, exIdx, t.catalogName(ex.id, ex.name))),+ Container(width: 1, height: 12, color: gc.border),+ ],+ _textAction(gc, t.finishSession, fit.finishSession),]),],);}+ Widget _nextRow(GymColors gc, String id) {+ final target = fit.nextTarget(id)!;+ return Padding(+ padding: const EdgeInsets.only(top: 4),+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(t.nextTime,+ style: AppTheme.f(11, weight: FontWeight.w600, color: gc.brass, letterSpacing: 0.4)),+ const SizedBox(width: 8),+ Expanded(+ child: RichText(+ text: TextSpan(+ text: fit.nextTargetLabel(id),+ style: AppTheme.f(12,+ weight: FontWeight.w600, color: target.up ? gc.ember : gc.textSecondary),+ children: [+ if (!target.up)+ TextSpan(+ text: ' · ${t.nextHold}',+ style: AppTheme.f(11.5, weight: FontWeight.w400, color: gc.textTertiary)),+ ],+ ),+ ),+ ),+ ],+ ),+ );+ }+Widget _restNudge(GymColors gc, String glyph, String semantic, VoidCallback onTap) {return Semantics(button: true,@@ -269,7 +261,7 @@ class SessionScreen extends StatelessWidget {child: Container(padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),decoration: BoxDecoration(color: gc.bgRaised2, borderRadius: BorderRadius.circular(8)),- child: Text(glyph, style: AppTheme.s(12, weight: FontWeight.w600, color: gc.text)),+ child: Text(glyph, style: AppTheme.f(12, weight: FontWeight.w600, color: gc.text)),),),),@@ -287,14 +279,14 @@ class SessionScreen extends StatelessWidget {if (ok) fit.removeSessionExercise(exIdx);}- static const _numCol = 24.0;+ static const _numCol = 26.0;static const _checkCol = 40.0;- static const _gap = 6.0;+ static const _gap = 10.0;static const _cardPad = 8.0;- static const _rowPad = 8.0;+ static const _rowPad = 14.0;Widget _setsHeader(GymColors gc, bool repsOnly) {- final s = AppTheme.s(11, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1);+ final s = AppTheme.f(11, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4);Widget label(String t) => FittedBox(fit: BoxFit.scaleDown,@@ -314,13 +306,86 @@ class SessionScreen extends StatelessWidget {]);}+ Widget _liveBar(GymColors gc) {+ return Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ Row(children: [+ Container(+ width: 8,+ height: 8,+ decoration: BoxDecoration(+ color: fit.sessionPaused ? gc.textTertiary : gc.ember, shape: BoxShape.circle),+ ),+ const SizedBox(width: 8),+ Text(+ fit.sessionPaused ? t.paused : t.inProgress,+ style: AppTheme.f(12,+ weight: FontWeight.w600,+ color: fit.sessionPaused ? gc.textTertiary : gc.ember,+ letterSpacing: 0.4),+ ),+ ]),+ Row(children: [+ Text(fit.elapsedLabel,+ style: AppTheme.f(18,+ weight: FontWeight.w700, color: fit.sessionPaused ? gc.textSecondary : gc.text)),+ const SizedBox(width: 10),+ Semantics(+ button: true,+ label: fit.sessionPaused ? t.resumeWorkout : t.pauseWorkout,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: fit.toggleSessionPause,+ child: SizedBox(+ width: 48,+ height: 48,+ child: Center(+ child: Container(+ width: 36,+ height: 36,+ decoration: BoxDecoration(+ color: fit.sessionPaused ? gc.ember : gc.bgRaised2,+ shape: BoxShape.circle,+ border: Border.all(color: fit.sessionPaused ? gc.ember : gc.border),+ ),+ child: Icon(+ fit.sessionPaused ? PhosphorIconsFill.play : PhosphorIconsFill.pause,+ size: 16,+ color: fit.sessionPaused ? gc.onEmber : gc.text,+ ),+ ),+ ),+ ),+ ),+ ),+ ]),+ ],+ );+ }++ Widget _manualBar(GymColors gc, WorkoutSession s) {+ return Row(children: [+ Icon(PhosphorIconsRegular.calendarPlus, size: 15, color: gc.brass),+ const SizedBox(width: 8),+ Expanded(+ child: Text(+ '${t.logging} · ${t.longDate(s.loggedAt ?? DateTime.now())}',+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(12.5, weight: FontWeight.w700, color: gc.brass, letterSpacing: 0.6),+ ),+ ),+ ]);+ }+Widget _setRow(GymColors gc, int exIdx, int j, SessionSet st, bool repsOnly) {return Container(margin: const EdgeInsets.only(bottom: 2),- padding: const EdgeInsets.symmetric(horizontal: _rowPad, vertical: 8),+ padding: const EdgeInsets.symmetric(horizontal: _rowPad, vertical: 10),decoration: BoxDecoration(color: st.done ? gc.sageSoft : Colors.transparent,- borderRadius: BorderRadius.circular(10),+ borderRadius: BorderRadius.circular(14),),child: Row(children: [SizedBox(@@ -391,7 +456,7 @@ class SessionScreen extends StatelessWidget {decoration: BoxDecoration(color: st.done ? gc.sage : Colors.transparent,shape: BoxShape.circle,- border: Border.all(color: st.done ? gc.sage : gc.border, width: 2),+ border: Border.all(color: st.done ? gc.sage : gc.textTertiary, width: 2),),child: st.done? Center(child: SvgPathIcon(Ic.checkBold, size: 14, color: Colors.white))@@ -411,39 +476,48 @@ class SessionScreen extends StatelessWidget {child: Container(padding: const EdgeInsets.all(10),decoration: BoxDecoration(- border: Border.all(color: gc.border),borderRadius: BorderRadius.circular(12),),child: FittedBox(fit: BoxFit.scaleDown,child: Text(label,maxLines: 1,- style: AppTheme.s(13,- weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1)),+ style: AppTheme.f(13,+ weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4)),),),);- Widget _plateRow(GymColors gc, SessionExercise ex) {+ Widget _plateRow(BuildContext context, GymColors gc, SessionExercise ex) {final exercise = fit.exerciseById(ex.id);- if (exercise == null) return const SizedBox.shrink();+ if (exercise == null || ex.sets.isEmpty) return const SizedBox.shrink();final next = ex.sets.firstWhere((s) => !s.done, orElse: () => ex.sets.last);final hint = fit.plateHint(exercise.equipment, next.weight);if (hint == null) return const SizedBox.shrink();- return Padding(- padding: const EdgeInsets.fromLTRB(_rowPad, 8, _rowPad, 0),- child: Row(- children: [- Icon(PhosphorIconsRegular.circlesThree, size: 13, color: gc.textTertiary),- const SizedBox(width: 7),- Expanded(- child: Text(t.platesPerSide(hint),- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: AppTheme.s(11.5, color: gc.textTertiary)),+ return Semantics(+ button: true,+ label: t.toolTitle('plate'),+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => showPlateSheet(context, fit.toDisplayWeight(next.weight)),+ child: Padding(+ padding: const EdgeInsets.fromLTRB(_rowPad, 8, _rowPad, 0),+ child: Row(+ children: [+ Icon(PhosphorIconsRegular.circlesThree, size: 13, color: gc.textTertiary),+ const SizedBox(width: 7),+ Expanded(+ child: Text(t.platesPerSide(hint),+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary)),+ ),+ const SizedBox(width: 6),+ Icon(PhosphorIconsRegular.caretRight, size: 12, color: gc.textTertiary),+ ],),- ],+ ),),);}@@ -468,85 +542,127 @@ class SessionScreen extends StatelessWidget {for (var i = 0; i <= j && i < sets.length; i++) {if (sets[i].counts) working++;}- final text = st.kind == SetKind.warmup+ final base = st.kind == SetKind.warmup? 'W': switch (st.kind) {SetKind.drop => '$working·D',SetKind.failure => '$working·F',_ => '$working',};+ final text = st.rpe == null ? base : '$base@${fmt(st.rpe!)}';return FittedBox(fit: BoxFit.scaleDown,alignment: Alignment.centerLeft,child: Text(text,maxLines: 1,softWrap: false,- style: AppTheme.d(16, weight: FontWeight.w700, color: _kindColor(gc, st.kind))),+ style: AppTheme.f(16, weight: FontWeight.w700, color: _kindColor(gc, st.kind))),);}Future<void> _kindSheet(BuildContext context, int exIdx, int j, SetKind current) async {final gc = context.gc;- final picked = await showModalBottomSheet<SetKind>(+ await showModalBottomSheet<void>(context: context,backgroundColor: Colors.transparent,- builder: (sheet) => Container(- padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),- decoration: BoxDecoration(- color: gc.bgRaised,- border: Border.all(color: gc.border),- 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.setType,- style: AppTheme.d(12,- weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 2)),- const SizedBox(height: 12),- for (final kind in SetKind.values) ...[- if (kind != SetKind.values.first) const SizedBox(height: 8),- GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () => Navigator.of(sheet).pop(kind),- child: Container(- padding: const EdgeInsets.all(15),- decoration: BoxDecoration(- color: kind == current ? gc.bgRaised2 : Colors.transparent,- borderRadius: BorderRadius.circular(14),- border: Border.all(color: kind == current ? _kindColor(gc, kind) : gc.border),- ),- child: Row(children: [- Container(- width: 8,- height: 8,- decoration:- BoxDecoration(color: _kindColor(gc, kind), shape: BoxShape.circle),- ),- const SizedBox(width: 12),- Expanded(- child: Text(_kindLabel(kind),- style: AppTheme.s(14, weight: FontWeight.w600, color: gc.text)),+ isScrollControlled: true,+ builder: (sheet) => StatefulBuilder(+ builder: (sheet, setSheet) {+ final live = fit.session?.exercises[exIdx].sets[j];+ final kindNow = live?.kind ?? current;+ return Container(+ padding: sheetPad(sheet),+ decoration: BoxDecoration(+ color: gc.bgRaised,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),+ ),+ child: SingleChildScrollView(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: [+ const SheetHandle(),+ const SizedBox(height: 18),+ Text(t.setType,+ style: AppTheme.f(12,+ weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4)),+ const SizedBox(height: 12),+ for (final kind in SetKind.values) ...[+ if (kind != SetKind.values.first) const SizedBox(height: 8),+ GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => setSheet(() => fit.setSetKind(exIdx, j, kind)),+ child: Container(+ padding: const EdgeInsets.all(15),+ decoration: BoxDecoration(+ color: kind == kindNow ? gc.bgRaised2 : Colors.transparent,+ borderRadius: BorderRadius.circular(14),+ border:+ Border.all(color: kind == kindNow ? _kindColor(gc, kind) : gc.border),+ ),+ child: Row(children: [+ Container(+ width: 8,+ height: 8,+ decoration:+ BoxDecoration(color: _kindColor(gc, kind), shape: BoxShape.circle),+ ),+ const SizedBox(width: 12),+ Expanded(+ child: Text(_kindLabel(kind),+ style: AppTheme.f(14, weight: FontWeight.w600, color: gc.text)),+ ),+ if (kind == kindNow)+ Icon(PhosphorIconsBold.check, size: 14, color: _kindColor(gc, kind)),+ ]),+ ),),- if (kind == current)- Icon(PhosphorIconsBold.check, size: 14, color: _kindColor(gc, kind)),- ]),- ),+ ],+ const SizedBox(height: 14),+ Text(t.setTypeHint, style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary, height: 1.4)),+ if (fit.logRpe) ...[+ const SizedBox(height: 20),+ Text(t.rpeTitle,+ style: AppTheme.f(12,+ weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4)),+ const SizedBox(height: 10),+ Wrap(spacing: 8, runSpacing: 8, children: [+ Pill(+ label: t.none,+ bg: live?.rpe == null ? gc.ember : gc.bgRaised2,+ fg: live?.rpe == null ? gc.onEmber : gc.textSecondary,+ onTap: () => setSheet(() => fit.setSessionRpe(exIdx, j, null)),+ hPad: 12,+ vPad: 7,+ fontSize: 12.5,+ ),+ for (final value in _rpeSteps)+ Pill(+ label: fmt(value),+ bg: live?.rpe == value ? gc.ember : gc.bgRaised2,+ fg: live?.rpe == value ? gc.onEmber : gc.textSecondary,+ onTap: () => setSheet(() => fit.setSessionRpe(exIdx, j, value)),+ hPad: 12,+ vPad: 7,+ fontSize: 12.5,+ ),+ ]),+ const SizedBox(height: 10),+ Text(t.rpeHint, style: AppTheme.f(11.5, weight: FontWeight.w500, color: gc.textTertiary, height: 1.4)),+ ],+ const SizedBox(height: 18),+ PrimaryButton(label: t.done, onTap: () => Navigator.of(sheet).pop()),+ ],),- ],- const SizedBox(height: 14),- Text(t.setTypeHint,- style: AppTheme.s(11.5, color: gc.textTertiary, height: 1.4)),- ],- ),+ ),+ );+ },),);- if (picked != null) fit.setSetKind(exIdx, j, picked);}+ static const _rpeSteps = [6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0];+Widget _miniStepper(GymColors gc,String value,@@ -577,12 +693,14 @@ class SessionScreen extends StatelessWidget {),);return Builder(- builder: (context) => Row(- mainAxisSize: MainAxisSize.min,- children: [- b('–', t.decrease, dec),- const SizedBox(width: 3),- GestureDetector(+ builder: (context) => FittedBox(+ fit: BoxFit.scaleDown,+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ b('–', t.decrease, dec),+ const SizedBox(width: 3),+ GestureDetector(behavior: HitTestBehavior.opaque,onTap: () => onEdit(context),child: Container(@@ -596,6 +714,7 @@ class SessionScreen extends StatelessWidget {const SizedBox(width: 3),b('+', t.increase, inc),],+ ),),);}@@ -611,18 +730,60 @@ class SessionScreen extends StatelessWidget {if (parsed != null) onSave(parsed);}- Widget _circleBtn(GymColors gc, List<IconPath> icon, VoidCallback onTap) {- return GestureDetector(- onTap: onTap,- child: Container(- width: 50,- height: 50,- decoration: BoxDecoration(- color: gc.bgRaised,- shape: BoxShape.circle,- border: Border.all(color: gc.border),+ Widget _mainAction(GymColors gc, SessionExercise? ex, int exIdx, int total) {+ final pending = ex == null ? -1 : ex.sets.indexWhere((st) => !st.done);+ if (pending >= 0) {+ return PrimaryButton(label: t.setDone, onTap: () => fit.toggleSet(exIdx, pending), height: 56);+ }+ if (exIdx < total - 1) {+ return PrimaryButton(label: t.nextExercise, onTap: fit.nextExercise, height: 56);+ }+ return PrimaryButton(label: t.finishSession, onTap: fit.finishSession, height: 56);+ }++ Future<void> _goNext(BuildContext context, SessionExercise? ex) async {+ if (ex != null && ex.sets.isNotEmpty && !ex.sets.any((st) => st.done)) {+ final ok = await askConfirm(+ context,+ title: t.skipExercise,+ body: t.skipExerciseBody(t.catalogName(ex.id, ex.name)),+ confirmLabel: t.skip2,+ );+ if (!ok) return;+ }+ fit.nextExercise();+ }++ Widget _textAction(GymColors gc, String label, VoidCallback onTap) => Semantics(+ button: true,+ child: GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),+ child: Text(label,+ style: AppTheme.f(12, weight: FontWeight.w600, color: gc.textTertiary)),+ ),+ ),+ );++ Widget _circleBtn(GymColors gc, List<IconPath> icon, VoidCallback onTap, {bool enabled = true}) {+ return Semantics(+ button: true,+ enabled: enabled,+ child: GestureDetector(+ onTap: enabled ? onTap : null,+ child: Container(+ width: 50,+ height: 50,+ decoration: BoxDecoration(+ color: enabled ? gc.bgRaised : Colors.transparent,+ shape: BoxShape.circle,+ ),+ child: Center(+ child: SvgPathIcon(icon, size: 18, color: enabled ? gc.text : gc.textTertiary),+ ),),- child: Center(child: SvgPathIcon(icon, size: 18, color: gc.text)),),);}@@ -665,13 +826,23 @@ class SessionScreen extends StatelessWidget {decoration: BoxDecoration(color: gc.bgRaised,shape: BoxShape.circle,- border: Border.all(color: gc.border),),child: Icon(PhosphorIconsRegular.shareNetwork, size: 20, color: gc.text),),),),]),+ const SizedBox(height: 10),+ GhostButton(+ label: t.saveAsRoutine,+ icon: PhosphorIconsRegular.listChecks,+ onTap: () {+ if (fit.saveSessionAsRoutine().isEmpty) return;+ ScaffoldMessenger.of(context).showSnackBar(+ SnackBar(content: Text(t.savedAsRoutine), behavior: SnackBarBehavior.floating),+ );+ },+ ),],),);@@ -683,7 +854,7 @@ class SessionScreen extends StatelessWidget {child: Container(decoration: BoxDecoration(color: gc.bgRaised,- border: Border.all(color: prs > 0 ? gc.accent : gc.border),+borderRadius: BorderRadius.circular(24),),child: Stack(@@ -712,8 +883,8 @@ class SessionScreen extends StatelessWidget {crossAxisAlignment: CrossAxisAlignment.start,children: [Row(children: [- Text(t.sessionComplete,- style: AppTheme.d(11, weight: FontWeight.w600, color: gc.brass, letterSpacing: 3)),+ Text(t.sessionComplete.toUpperCase(),+ style: AppTheme.f(11, weight: FontWeight.w600, color: gc.brass, letterSpacing: 1.4)),if (prs > 0) ...[const SizedBox(width: 8),Container(@@ -721,7 +892,7 @@ class SessionScreen extends StatelessWidget {decoration:BoxDecoration(color: gc.accentSoft, borderRadius: BorderRadius.circular(100)),child: Text(t.prCount(prs),- style: AppTheme.s(10, weight: FontWeight.w700, color: gc.accent)),+ style: AppTheme.f(10, weight: FontWeight.w700, color: gc.accent)),),],]),@@ -729,13 +900,13 @@ class SessionScreen extends StatelessWidget {ConstrainedBox(constraints: const BoxConstraints(maxWidth: 210),child: Text(t.finishHeadline(prs: prs, streak: streak, goalHit: goalHit),- style: AppTheme.d(28, weight: FontWeight.w700, color: gc.text, height: 1.05)),+ style: AppTheme.f(28, weight: FontWeight.w700, color: gc.text, height: 1.05)),),const SizedBox(height: 8),ConstrainedBox(constraints: const BoxConstraints(maxWidth: 230),child: Text(t.finishBody(prs: prs, streak: streak, goalHit: goalHit),- style: AppTheme.s(13, color: gc.textSecondary, height: 1.35)),+ style: AppTheme.f(13, weight: FontWeight.w500, color: gc.textSecondary, height: 1.35)),),],),@@ -758,10 +929,10 @@ class SessionScreen extends StatelessWidget {const SizedBox(width: 12),Expanded(child: Text(t.vsLastTime,- style: AppTheme.s(11, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1)),+ style: AppTheme.f(11, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4)),),Text('${up ? '+' : ''}$pct%',- style: AppTheme.d(16, weight: FontWeight.w700, color: up ? gc.sage : gc.textSecondary)),+ style: AppTheme.f(16, weight: FontWeight.w700, color: up ? gc.sage : gc.textSecondary)),]),);}@@ -773,7 +944,7 @@ class SessionScreen extends StatelessWidget {child: Row(children: [SvgPathIcon(Ic.flame, size: 16, color: gc.accent),const SizedBox(width: 12),- Expanded(child: Text(t.firstTime, style: AppTheme.s(13, color: gc.textSecondary))),+ Expanded(child: Text(t.firstTime, style: AppTheme.f(13, weight: FontWeight.w500, color: gc.textSecondary))),]),);}@@ -785,9 +956,9 @@ class SessionScreen extends StatelessWidget {child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- Text(label, style: AppTheme.s(10, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1)),+ Text(label, style: AppTheme.f(10, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 0.4)),const SizedBox(height: 4),- Text(value, style: AppTheme.d(18, weight: FontWeight.w700, color: gc.text)),+ Text(value, style: AppTheme.f(18, weight: FontWeight.w700, color: gc.text)),],),);@@ -821,7 +992,7 @@ void showAddToSessionSheet(BuildContext context) {crossAxisAlignment: CrossAxisAlignment.stretch,children: [Text(t.addExercise,- style: AppTheme.d(15, weight: FontWeight.w700, color: gc.text, letterSpacing: 2)),+ style: AppTheme.f(15, weight: FontWeight.w700, color: gc.text, letterSpacing: 0.4)),const SizedBox(height: 14),SearchField(controller: search,@@ -831,7 +1002,7 @@ void showAddToSessionSheet(BuildContext context) {),const SizedBox(height: 12),Text(q.isEmpty ? t.suggested.toUpperCase() : t.results.toUpperCase(),- style: AppTheme.s(11,+ style: AppTheme.f(11,weight: FontWeight.w700, color: gc.textTertiary, letterSpacing: 1.5)),],),@@ -844,7 +1015,7 @@ void showAddToSessionSheet(BuildContext context) {if (list.isEmpty)Padding(padding: const EdgeInsets.symmetric(vertical: 18),- child: Text(t.noMatches, style: AppTheme.s(13, color: gc.textSecondary)),+ child: Text(t.noMatches, style: AppTheme.f(13, weight: FontWeight.w500, color: gc.textSecondary)),),for (final ex in list) _addRow(sheetCtx, gc, ex),],@@ -889,7 +1060,6 @@ Widget _addRow(BuildContext sheetCtx, GymColors gc, Exercise ex) {padding: const EdgeInsets.all(10),decoration: BoxDecoration(color: gc.bgRaised2,- border: Border.all(color: gc.border),borderRadius: BorderRadius.circular(14),),child: Row(children: [@@ -902,9 +1072,9 @@ Widget _addRow(BuildContext sheetCtx, GymColors gc, Exercise ex) {Text(exerciseName(ex),maxLines: 1,overflow: TextOverflow.ellipsis,- style: AppTheme.s(13.5, weight: FontWeight.w600, color: gc.text)),+ style: AppTheme.f(13.5, weight: FontWeight.w600, color: gc.text)),const SizedBox(height: 2),- Text(muscleLabel(ex.primary), style: AppTheme.s(11, color: gc.textSecondary)),+ Text(muscleLabel(ex.primary), style: AppTheme.f(11, weight: FontWeight.w500, color: gc.textSecondary)),],),),diff --git a/lib/state/workout_state.dart b/lib/state/workout_state.dartindex 7b13a05..93dbdaf 100644--- a/lib/state/workout_state.dart+++ b/lib/state/workout_state.dart@@ -10,8 +10,10 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStDateTime? _runningSince;int _elapsedBefore = 0;bool sessionPaused = false;+ DateTime? logDay;- void startWorkout([List<String>? initialMuscles]) {+ void startWorkout([List<String>? initialMuscles, DateTime? on]) {+ logDay = on;selectedMuscles..clear()..addAll(initialMuscles ?? const []);@@ -21,6 +23,14 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStvoid startFocusWorkout() => startWorkout(suggestedFocus.muscles);+ void startPicking({DateTime? on}) {+ logDay = on;+ selectedMuscles.clear();+ sessionPicks.clear();+ trainStep = 'review';+ pushRoute('train');+ }+List<Exercise> getFilteredExercises(List<String> sel) {if (sel.isEmpty) return const [];return allExercises@@ -103,31 +113,94 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSttrainStep = 'select';selectedMuscles.clear();sessionPicks.clear();+ logDay = null;popRoute();}- void startRoutine(Routine r) {+ void startRoutine(Routine r, {DateTime? on}) {final exs = routineExercises(r);if (exs.isEmpty) return;- _beginSession(exs);+ _beginSession(exs,+ plan: {for (final ex in exs) ex.id: routineSets(r, ex.id)},+ chained: {for (final ex in exs) if (chainsToNext(r, ex.id)) ex.id},+ on: on);}void startSession() {final exs = allExercises.where((e) => sessionPicks.contains(e.id)).toList();- if (exs.isNotEmpty) _beginSession(exs);+ if (exs.isNotEmpty) _beginSession(exs, on: logDay);+ }++ List<SessionSet> _openingSets(String id, {int? count}) {+ final sets = _workingOpeners(id, count: count);+ if (!warmsUp(id) || isRepsOnly(id)) return sets;+ return [..._warmupFor(sets), ...sets];+ }++ List<SessionSet> _workingOpeners(String id, {int? count}) {+ final last = lastSetsFor(id).where((l) => l.counts).toList();+ final List<SessionSet> base;+ if (last.isNotEmpty) {+ final bump = _progressBump(id, last);+ base = last.map((l) => SessionSet(l.reps, l.weight + bump, false)).toList();+ } else {+ final w = isRepsOnly(id) ? 0.0 : 20.0;+ base = [for (var i = 0; i < kDefaultRoutineSets; i++) SessionSet(10, w, false)];+ }+ if (count == null || count == base.length) return base;+ if (count < base.length) return base.take(count).toList();+ final fill = base.last;+ return [+ ...base,+ for (var i = base.length; i < count; i++) SessionSet(fill.reps, fill.weight, false),+ ];}- List<SessionSet> _openingSets(String id) {- final last = lastSetsFor(id);- if (last.isNotEmpty) return last.map((l) => SessionSet(l.reps, l.weight, false)).toList();- final w = isRepsOnly(id) ? 0.0 : 20.0;- return [SessionSet(10, w, false), SessionSet(10, w, false), SessionSet(10, w, false)];+ ({double weightKg, int reps, bool up})? nextTarget(String id) {+ final last = lastSetsFor(id).where((l) => l.counts).toList();+ if (last.isEmpty) return null;+ final reps = last.first.reps;+ if (reps <= 0) return null;+ final hit = last.every((l) => l.reps >= reps);+ if (isRepsOnly(id)) return (weightKg: 0, reps: hit ? reps + 1 : reps, up: hit);+ final top = last.map((l) => l.weight).reduce(math.max);+ final step = progressStep[id] ?? fromDisplayWeight(weightStep);+ return (weightKg: hit ? top + step : top, reps: reps, up: hit);}- void _beginSession(List<Exercise> exs) {+ String? nextTargetLabel(String id) {+ final target = nextTarget(id);+ if (target == null) return null;+ if (isRepsOnly(id)) return '${target.reps} ${t.repsCol.toLowerCase()}';+ return '${weightLabel(target.weightKg)} × ${target.reps}';+ }++ double _progressBump(String id, List<LoggedSet> last) {+ final step = progressStep[id] ?? 0;+ if (step <= 0) return 0;+ final working = last.where((l) => l.counts).toList();+ if (working.isEmpty) return 0;+ final target = working.first.reps;+ if (working.any((l) => l.reps < target)) return 0;+ return step;+ }++ void _beginSession(List<Exercise> exs,+ {Map<String, int>? plan, Set<String> chained = const {}, DateTime? on}) {final s = WorkoutSession();+ if (on != null) {+ s.loggedAt = DateTime(on.year, on.month, on.day, 12);+ s.manual = true;+ }+ logDay = null;s.exercises = exs- .map((ex) => SessionExercise(ex.id, ex.name, ex.primary, _openingSets(ex.id)))+ .map((ex) => SessionExercise(+ ex.id,+ ex.name,+ ex.primary,+ _openingSets(ex.id, count: plan?[ex.id]),+ linkedNext: chained.contains(ex.id),+ )).toList();_restTimer?.cancel();_elapsedBefore = 0;@@ -150,15 +223,22 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt: _elapsedBefore + DateTime.now().difference(_runningSince!).inSeconds;void toggleSessionPause() {+ final s = session;if (sessionPaused) {_startTicking();sessionPaused = false;+ final frozen = s?.restFrozen;+ if (frozen != null) _armRest(frozen);} else {_elapsedBefore = sessionElapsed;_runningSince = null;_sessionTimer?.cancel();_restTimer?.cancel();RestAlarm.instance.cancel();+ if (s != null) {+ s.restFrozen = s.restRemaining;+ s.restEndsAt = null;+ }sessionPaused = true;}persistNow();@@ -184,47 +264,137 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStvoid toggleSet(int exIdx, int setIdx) {final st = session!.exercises[exIdx].sets[setIdx];+ _advanceTimer?.cancel();st.done = !st.done;_persist();notifyListeners();- if (st.done) startRest();+ if (!st.done) return;+ final chain = chainAt(exIdx);+ if (chain.length > 1) {+ _advanceChain(chain, exIdx);+ return;+ }+ startRest();+ if (autoAdvance) _advanceWhenDone(exIdx);+ }++ List<int> chainAt(int exIdx) {+ final s = session;+ if (s == null || exIdx < 0 || exIdx >= s.exercises.length) return const [];+ var start = exIdx;+ while (start > 0 && s.exercises[start - 1].linkedNext) {+ start--;+ }+ final chain = <int>[start];+ var i = start;+ while (i < s.exercises.length - 1 && s.exercises[i].linkedNext) {+ chain.add(++i);+ }+ return chain;+ }++ bool get inSuperset => chainAt(session?.currentIndex ?? -1).length > 1;++ void _advanceChain(List<int> chain, int exIdx) {+ final s = session!;+ final after = chain.where((i) => i > exIdx && s.exercises[i].hasUndone).toList();+ if (after.isNotEmpty) {+ s.currentIndex = after.first;+ _persist();+ notifyListeners();+ return;+ }+ startRest();+ final left = chain.where((i) => s.exercises[i].hasUndone).toList();+ if (left.isNotEmpty) {+ s.currentIndex = left.first;+ } else if (autoAdvance && chain.last < s.exercises.length - 1) {+ s.currentIndex = chain.last + 1;+ }+ _persist();+ notifyListeners();+ }++ static const advanceDelay = Duration(milliseconds: 900);++ Timer? _advanceTimer;++ void _advanceWhenDone(int exIdx) {+ final s = session;+ if (s == null || exIdx != s.currentIndex || exIdx >= s.exercises.length - 1) return;+ if (s.exercises[exIdx].sets.any((st) => !st.done)) return;+ _advanceTimer?.cancel();+ _advanceTimer = Timer(advanceDelay, () {+ final live = session;+ if (live == null || live.currentIndex != exIdx) return;+ if (live.exercises[exIdx].sets.any((st) => !st.done)) return;+ live.currentIndex = exIdx + 1;+ _persist();+ notifyListeners();+ });}void startRest() {- if (sessionPaused) return;+ if (sessionPaused || session?.manual == true) return;_restTimer?.cancel();RestAlarm.instance.stopSound();final seconds = restFor(session!.exercises.isEmpty? '': session!.exercises[session!.currentIndex.clamp(0, session!.exercises.length - 1)].id);- session!.restRemaining = seconds;+ if (seconds <= 0) {+ session!.clearRest();+ notifyListeners();+ return;+ }- RestAlarm.instance.schedule(Duration(seconds: seconds));+ _armRest(seconds);askAlarmPermission();notifyListeners();+ }++ void _armRest(int seconds) {+ final s = session;+ if (s == null) return;+ _restTimer?.cancel();+ s.restFrozen = null;+ s.restEndsAt = DateTime.now().add(Duration(seconds: seconds));+ RestAlarm.instance.schedule(Duration(seconds: seconds));_restTimer = Timer.periodic(const Duration(seconds: 1), (t) {- final s = session;- if (s == null || s.restRemaining == null) {+ final live = session;+ if (live == null || live.restEndsAt == null) {t.cancel();return;}- final next = s.restRemaining! - 1;- s.restRemaining = next <= 0 ? null : next;- if (next <= 0) {+ if (live.restRemaining == null) {+ live.clearRest();t.cancel();-RestAlarm.instance.fireNow();}notifyListeners();});}+ void syncRest() {+ final s = session;+ if (s == null || s.restEndsAt == null) return;+ final left = s.restRemaining;+ if (left == null) {+ _restTimer?.cancel();+ s.clearRest();+ RestAlarm.instance.cancel();+ } else if (!(_restTimer?.isActive ?? false)) {+ _armRest(left);+ } else {+ return;+ }+ notifyListeners();+ }+void nudgeRest(int seconds) {final s = session;- if (s == null || s.restRemaining == null) return;- final left = (s.restRemaining! + seconds).clamp(5, 600);- s.restRemaining = left;- RestAlarm.instance.schedule(Duration(seconds: left));+ final left = s?.restRemaining;+ if (s == null || left == null) return;+ _armRest((left + seconds).clamp(5, 600));notifyListeners();}@@ -232,7 +402,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt_restTimer?.cancel();RestAlarm.instance.cancel();RestAlarm.instance.stopSound();- session?.restRemaining = null;+ session?.clearRest();notifyListeners();}@@ -255,6 +425,21 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStstatic const _warmupSpec = [(0.4, 10), (0.6, 5), (0.8, 3)];+ List<SessionSet> _warmupFor(List<SessionSet> sets) {+ if (sets.isEmpty) return const [];+ final target = sets.map((st) => st.weight).reduce(math.max);+ if (target <= 0) return const [];+ return [+ for (final spec in _warmupSpec)+ SessionSet(+ spec.$2,+ fromDisplayWeight(_roundTo(toDisplayWeight(target * spec.$1), weightStep)),+ false,+ kind: SetKind.warmup,+ ),+ ];+ }+bool hasWarmup(int exIdx) {final s = session;if (s == null || exIdx >= s.exercises.length) return false;@@ -265,25 +450,24 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStfinal s = session;if (s == null || exIdx >= s.exercises.length) return;final sets = s.exercises[exIdx].sets;- if (sets.isEmpty || hasWarmup(exIdx)) return;-- final target = sets.map((st) => st.weight).reduce(math.max);- if (target <= 0) return;-- final warm = [- for (final spec in _warmupSpec)- SessionSet(- spec.$2,- fromDisplayWeight(_roundTo(toDisplayWeight(target * spec.$1), weightStep)),- false,- kind: SetKind.warmup,- ),- ];+ if (hasWarmup(exIdx)) return;+ final warm = _warmupFor(sets);+ if (warm.isEmpty) return;sets.insertAll(0, warm);_persist();notifyListeners();}+ void setSessionRpe(int exIdx, int setIdx, double? rpe) {+ final s = session;+ if (s == null || exIdx >= s.exercises.length) return;+ final sets = s.exercises[exIdx].sets;+ if (setIdx >= sets.length) return;+ sets[setIdx].rpe = rpe;+ _persist();+ notifyListeners();+ }+void setSetKind(int exIdx, int setIdx, SetKind kind) {final s = session;if (s == null || exIdx >= s.exercises.length) return;@@ -369,6 +553,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt}void finishSession() {+ _advanceTimer?.cancel();_sessionTimer?.cancel();_restTimer?.cancel();RestAlarm.instance.cancel();@@ -384,16 +569,16 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt}s.summaryVolume = working.fold<double>(0, (sum, st) => sum + st.reps * st.weight).round();s.summarySets = working.length;- s.summaryDuration = sessionElapsed;+ s.summaryDuration = s.manual ? _elapsedBefore : sessionElapsed;s.complete = true;- s.restRemaining = null;+ s.clearRest();if (done.isNotEmpty) {final logged = <LoggedExercise>[];for (final e in s.exercises) {final doneSets = e.sets.where((st) => st.done)- .map((st) => LoggedSet(st.reps, st.weight, kind: st.kind))+ .map((st) => LoggedSet(st.reps, st.weight, kind: st.kind, rpe: st.rpe)).toList();if (doneSets.isNotEmpty) {logged.add(LoggedExercise(e.id, e.name, e.primary, doneSets));@@ -409,7 +594,24 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt}persistNow();_refreshWidgets();+ syncTrainReminder();+ refreshAwards();+ notifyListeners();+ }++ String saveSessionAsRoutine() {+ final s = session;+ if (s == null || s.exercises.isEmpty) return '';+ final id = createRoutine(t.newRoutineName);+ for (final ex in s.exercises) {+ if (exerciseById(ex.id) == null) continue;+ toggleRoutineExercise(id, ex.id);+ final working = ex.sets.where((st) => st.kind != SetKind.warmup).length;+ bumpRoutineSets(id, ex.id, working - kDefaultRoutineSets);+ }+ persistNow();notifyListeners();+ return id;}double get summaryVolumeKg => (session?.summaryVolume ?? 0).toDouble();@@ -446,6 +648,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStsessions.remove(ls);final s = WorkoutSession()..loggedAt = ls.date+ ..manual = _dayKey(ls.date) != _dayKey(DateTime.now())..exercises = ls.exercises.map((e) => SessionExercise(e.id, e.name, e.primary,e.sets.map((x) => SessionSet(x.reps, x.weight, true)).toList()))@@ -467,6 +670,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt}void saveAndExit() {+ _advanceTimer?.cancel();_sessionTimer?.cancel();_restTimer?.cancel();RestAlarm.instance.cancel();@@ -477,6 +681,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStselectedMuscles.clear();sessionPicks.clear();trainStep = 'select';+ logDay = null;resetRoute('home');persistNow();notifyListeners();diff --git a/lib/widgets/stopwatch_card.dart b/lib/widgets/stopwatch_card.dartindex 62e63ef..4eade20 100644--- a/lib/widgets/stopwatch_card.dart+++ b/lib/widgets/stopwatch_card.dart@@ -1,11 +1,12 @@import 'dart:async';import 'package:flutter/material.dart';-import 'package:phosphor_flutter/phosphor_flutter.dart';+import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';import '../l10n/l10n.dart';import '../theme/app_colors.dart';import '../theme/app_theme.dart';+import 'ui_kit.dart';class StopwatchCard extends StatefulWidget {const StopwatchCard({super.key});@@ -55,22 +56,22 @@ class _StopwatchCardState extends State<StopwatchCard> {padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 16),decoration: BoxDecoration(color: gc.bgRaised,- border: Border.all(color: running ? gc.ember : gc.border),- borderRadius: BorderRadius.circular(16),+ borderRadius: BorderRadius.circular(20),),child: Row(children: [- Icon(PhosphorIconsRegular.timer, size: 20, color: running ? gc.ember : gc.textSecondary),- const SizedBox(width: 12),- Text(label, style: AppTheme.d(28, weight: FontWeight.w700, color: gc.text)),+ Icon(PhosphorIconsRegular.timer, size: 20, color: running ? gc.text : gc.textSecondary),+ const SizedBox(width: 14),+ Text(label,+ style: AppTheme.f(28, weight: FontWeight.w800, color: gc.text, height: 1)),const Spacer(),if (s > 0)GestureDetector(onTap: _reset,child: Padding(padding: const EdgeInsets.only(right: 14),- child: Text(t.reset,- style: AppTheme.s(12, weight: FontWeight.w600, color: gc.textSecondary, letterSpacing: 1)),+ child: Text(titleCase(t.reset),+ style: AppTheme.f(12.5, weight: FontWeight.w600, color: gc.textSecondary)),),),GestureDetector(