Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
State updates
InlitXe015825b857a
diff --git a/lib/models/live_session.dart b/lib/models/live_session.dartindex 7077267..5d759cb 100644--- a/lib/models/live_session.dart+++ b/lib/models/live_session.dart@@ -10,6 +10,7 @@ class SessionSet {int? rest;double weight;bool done;+ bool half = false;SetKind kind;double? rpe;int? sec;@@ -34,6 +35,7 @@ class SessionSet {if (goal != null) 'g': goal,'w': weight,'d': done,+ if (half && !done) 'h': true,if (kind != SetKind.normal) 'k': kind.index,if (rpe != null) 'e': rpe,if (sec != null) 't': sec,@@ -53,7 +55,7 @@ class SessionSet {note: j['n'] as String? ?? '',repsR: (j['rr'] as num?)?.toInt(),goal: j['g'] as String?,- );+ )..half = j['h'] as bool? ?? false;}class SessionExercise {@@ -99,6 +101,7 @@ class WorkoutSession {DateTime? loggedAt;DateTime? restEndsAt;int? restFrozen;+ bool restSwitch = false;int? summaryVolume;int? summarySets;int? summaryDuration;@@ -115,6 +118,7 @@ class WorkoutSession {void clearRest() {restEndsAt = null;restFrozen = null;+ restSwitch = false;}Map<String, dynamic> toJson() => {@@ -129,6 +133,7 @@ class WorkoutSession {'at': loggedAt?.toIso8601String(),if (restEndsAt != null) 're': restEndsAt!.toIso8601String(),if (restFrozen != null) 'rf': restFrozen,+ if (restSwitch && restEndsAt != null) 'rsw': true,'sv': summaryVolume,'ss': summarySets,'sd': summaryDuration,@@ -147,6 +152,7 @@ class WorkoutSession {..loggedAt = DateTime.tryParse((j['at'] as String?) ?? '')..restEndsAt = DateTime.tryParse((j['re'] as String?) ?? '')..restFrozen = (j['rf'] as num?)?.toInt()+ ..restSwitch = j['rsw'] as bool? ?? false..summaryVolume = (j['sv'] as num?)?.toInt()..summarySets = (j['ss'] as num?)?.toInt()..summaryDuration = (j['sd'] as num?)?.toInt();diff --git a/lib/state/fit_core.dart b/lib/state/fit_core.dartindex 420833f..2e1e211 100644--- a/lib/state/fit_core.dart+++ b/lib/state/fit_core.dart@@ -72,6 +72,7 @@ abstract class FitCore extends ChangeNotifier {final Map<String, int> exerciseRest = {};final Map<String, String> exerciseUnits = {};+ final Map<String, String> exerciseDistance = {};final Map<String, double> progressStep = {};final Map<String, int> holdStep = {};@@ -376,6 +377,24 @@ abstract class FitCore extends ChangeNotifier {String distanceLabel(double km) => '${distanceValue(km)} $distanceUnit';double get distanceStep => 0.1;++ String distanceUnitFor(String id) => exerciseDistance[id] ?? distanceUnit;++ bool isMiFor(String id) => distanceUnitFor(id) == 'mi';++ double toDisplayKmFor(String id, double km) => isMiFor(id) ? km / _kmPerMile : km;++ double fromDisplayKmFor(String id, double shown) => isMiFor(id) ? shown * _kmPerMile : shown;++ String distanceValueFor(String id, double km) => fmt((toDisplayKmFor(id, km) * 100).round() / 100);++ String distanceLabelFor(String id, double km) => '${distanceValueFor(id, km)} ${distanceUnitFor(id)}';++ void setExerciseDistance(String id, String unit) {+ unit == distanceUnit ? exerciseDistance.remove(id) : exerciseDistance[id] = unit;+ _persist();+ notifyListeners();+ }}String durationLabel(int sec) {diff --git a/lib/state/fit_state.dart b/lib/state/fit_state.dartindex b1d3212..a8be58d 100644--- a/lib/state/fit_state.dart+++ b/lib/state/fit_state.dart@@ -127,6 +127,8 @@ class FitState extends FitCore_applyLanguage(data['language'] as String? ?? language);restSeconds = (data['rest'] as num?)?.toInt() ?? 90;miniRestSeconds = (data['miniRest'] as num?)?.toInt() ?? 20;+ changeRestSeconds = (data['changeRest'] as num?)?.toInt() ?? 0;+ sideRestSeconds = (data['sideRest'] as num?)?.toInt() ?? 0;alarmSound = data['alarmSound'] as String?;alarmSoundName = data['alarmSoundName'] as String?;RestAlarm.instance.customSoundPath = alarmSoundPath;@@ -384,10 +386,18 @@ class FitState extends FitCore_elapsedBefore = (data['liveElapsed'] as num?)?.toInt() ?? 0;sessionPaused = data['livePaused'] as bool? ?? false;final started = data['liveStart'] as String?;- if (sessionPaused || started == null) {+ final since = started == null ? null : DateTime.tryParse(started);+ if (!sessionPaused && since != null && DateTime.now().difference(since) > const Duration(hours: 6)) {+ _elapsedBefore += const Duration(hours: 3).inSeconds;+ sessionPaused = true;+ _runningSince = null;+ resetRoute('home');+ return;+ }+ if (sessionPaused || since == null) {_runningSince = null;} else {- _runningSince = DateTime.tryParse(started);+ _runningSince = since;_startTicking(from: _runningSince);}if (!sessionPaused) syncRest();@@ -428,6 +438,10 @@ class FitState extends FitCore((data['exUnits'] as Map?) ?? const {}).forEach((k, v) {if (k is String && (v == 'kg' || v == 'lb')) exerciseUnits[k] = v as String;});+ exerciseDistance.clear();+ ((data['exDist'] as Map?) ?? const {}).forEach((k, v) {+ if (k is String && (v == 'km' || v == 'mi')) exerciseDistance[k] = v as String;+ });}void _loadRepsOnly(Map<String, dynamic> data) {@@ -540,6 +554,8 @@ class FitState extends FitCore'language': language,'rest': restSeconds,'miniRest': miniRestSeconds,+ 'changeRest': changeRestSeconds,+ 'sideRest': sideRestSeconds,'alarmSound': alarmSound,'alarmSoundName': alarmSoundName,if (NotifSound.uris.isNotEmpty)@@ -628,6 +644,7 @@ class FitState extends FitCore'media': exerciseMedia,'exRest': exerciseRest,if (exerciseUnits.isNotEmpty) 'exUnits': exerciseUnits,+ if (exerciseDistance.isNotEmpty) 'exDist': exerciseDistance,if (collapsedGroups.isNotEmpty) 'collapsedGroups': collapsedGroups.toList(),'progress': progressStep,if (holdStep.isNotEmpty) 'holdStep': holdStep,@@ -745,6 +762,7 @@ class FitState extends FitCoreassistedOff.clear();exerciseRest.clear();exerciseUnits.clear();+ exerciseDistance.clear();collapsedGroups.clear();progressStep.clear();holdStep.clear();@@ -867,6 +885,8 @@ class FitState extends FitCore_applyLanguage(map['language'] as String? ?? language);restSeconds = (map['rest'] as num?)?.toInt() ?? restSeconds;miniRestSeconds = (map['miniRest'] as num?)?.toInt() ?? miniRestSeconds;+ changeRestSeconds = (map['changeRest'] as num?)?.toInt() ?? changeRestSeconds;+ sideRestSeconds = (map['sideRest'] as num?)?.toInt() ?? sideRestSeconds;bgPattern = map['bg'] as String? ?? bgPattern;heatTone = map['heatTone'] as String? ?? heatTone;_loadToggles(map);diff --git a/lib/state/settings_state.dart b/lib/state/settings_state.dartindex 1406b6c..678540f 100644--- a/lib/state/settings_state.dart+++ b/lib/state/settings_state.dart@@ -26,6 +26,8 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {String alarmStyle = 'quiet';int restSeconds = 90;int miniRestSeconds = 20;+ int changeRestSeconds = 0;+ int sideRestSeconds = 0;String? alarmSound;String? alarmSoundName;@@ -339,6 +341,18 @@ mixin SettingsState on FitCore, ToolsState, LibraryState {notifyListeners();}+ void setChangeRest(int v) {+ changeRestSeconds = v <= 0 ? 0 : v.clamp(15, 900);+ _persist();+ notifyListeners();+ }++ void setSideRest(int v) {+ sideRestSeconds = v <= 0 ? 0 : v.clamp(5, 300);+ _persist();+ notifyListeners();+ }+int restFor(String exerciseId) =>exerciseRest[exerciseId] ?? (modeOf(exerciseId) == 'cardio' ? 0 : restSeconds);diff --git a/lib/state/stats_state.dart b/lib/state/stats_state.dartindex 71c8b93..5b78c36 100644--- a/lib/state/stats_state.dart+++ b/lib/state/stats_state.dart@@ -502,7 +502,7 @@ mixin StatsState on FitCore, ToolsState, LibraryState, SettingsState, TimelineStvoid setLoggedKmShown(LoggedExercise e, int i, double shown) {if (i < 0 || i >= e.sets.length) return;- _replaceLoggedSet(e, i, km: _round3(fromDisplayKm(math.max(0.0, shown))));+ _replaceLoggedSet(e, i, km: _round3(fromDisplayKmFor(e.id, math.max(0.0, shown))));}void bumpLoggedSec(LoggedExercise e, int i, int d) {@@ -514,9 +514,9 @@ mixin StatsState on FitCore, ToolsState, LibraryState, SettingsState, TimelineStvoid bumpLoggedKm(LoggedExercise e, int i, int dir) {if (i < 0 || i >= e.sets.length) return;- final shown = toDisplayKm(e.sets[i].km ?? 0);+ final shown = toDisplayKmFor(e.id, e.sets[i].km ?? 0);final next = math.max(0.0, ((shown / distanceStep).round() + dir) * distanceStep);- _replaceLoggedSet(e, i, km: _round3(fromDisplayKm(next)));+ _replaceLoggedSet(e, i, km: _round3(fromDisplayKmFor(e.id, next)));}bool loggedTimed(LoggedExercise e) =>@@ -1240,7 +1240,8 @@ mixin StatsState on FitCore, ToolsState, LibraryState, SettingsState, TimelineStfinal km = s.km ?? 0;final sec = s.sec;final w = id == null ? weightValue(s.weight) : weightValueFor(id, s.weight);- if (km > 0) return sec == null ? distanceLabel(km) : '${distanceLabel(km)} · ${durationLabel(sec)}';+ final d = id == null ? distanceLabel(km) : distanceLabelFor(id, km);+ if (km > 0) return sec == null ? d : '$d · ${durationLabel(sec)}';if (sec != null && s.reps <= 0) {return s.weight > 0 ? '$w × ${durationLabel(sec)}' : durationLabel(sec);}diff --git a/lib/state/tools_state.dart b/lib/state/tools_state.dartindex 4d05c63..23b24bf 100644--- a/lib/state/tools_state.dart+++ b/lib/state/tools_state.dart@@ -35,6 +35,10 @@ mixin ToolsState on FitCore {double ffmiHeight = 175;double ffmiWeight = 75;double ffmiBf = 15;+ String protGoal = 'hold';+ double protWeight = 75;+ double waterWeight = 75;+ int waterMinutes = 60;static const dotsLifts = ['qXTaZnJ', 'EIeI8Vf', 'ila4NZS'];@@ -53,6 +57,8 @@ mixin ToolsState on FitCore {ffmiHeight = profile.heightCm;ffmiWeight = profile.weightKg;ffmiSex = profile.sex;+ protWeight = profile.weightKg;+ waterWeight = profile.weightKg;}double bestLift(String id) => 0;@@ -74,6 +80,12 @@ mixin ToolsState on FitCore {pushRoute('tools-detail');}+ void selectTool(String id) {+ if (id == 'dots' || id == 'wilks') _seedDots();+ activeToolId = id;+ notifyListeners();+ }+void closeTool() => popRoute(fallback: 'tools');void backFromTools() => popRoute();@@ -365,4 +377,24 @@ mixin ToolsState on FitCore {void bumpFfmiBf(double d) { ffmiBf = _clamp(ffmiBf + d, 3, 60); notifyListeners(); }void bumpWarmupTarget(double d) { warmupTarget = _clamp(warmupTarget + d, 0, null); notifyListeners(); }++ (double, double) get _protPerKg => switch (protGoal) {+ 'lose' => (1.8, 2.2),+ 'gain' => (1.6, 2.2),+ _ => (1.4, 1.8),+ };++ int get protLow => (protWeight * _protPerKg.$1 / 5).round() * 5;++ int get protHigh => (protWeight * _protPerKg.$2 / 5).round() * 5;++ double get waterLiters => _round1((waterWeight * 35 + waterMinutes * 12) / 1000);++ void setProtGoal(String g) { protGoal = g; notifyListeners(); }++ void bumpProtWeight(double d) { protWeight = _clamp(protWeight + d, 30, 300); notifyListeners(); }++ void bumpWaterWeight(double d) { waterWeight = _clamp(waterWeight + d, 30, 300); notifyListeners(); }++ void bumpWaterMinutes(int d) { waterMinutes = (waterMinutes + d).clamp(0, 300); notifyListeners(); }}diff --git a/lib/state/workout_state.dart b/lib/state/workout_state.dartindex 8b96a69..7e977d1 100644--- a/lib/state/workout_state.dart+++ b/lib/state/workout_state.dart@@ -760,7 +760,9 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStString get elapsedLabel {final e = sessionElapsed;- return '${(e ~/ 60).toString().padLeft(2, '0')}:${(e % 60).toString().padLeft(2, '0')}';+ final ss = (e % 60).toString().padLeft(2, '0');+ if (e < 3600) return '${(e ~/ 60).toString().padLeft(2, '0')}:$ss';+ return '${e ~/ 3600}:${(e % 3600 ~/ 60).toString().padLeft(2, '0')}:$ss';}SessionExercise? get currentExercise {@@ -775,9 +777,28 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStreturn t.exerciseXofY(s.currentIndex + 1, s.exercises.length);}+ bool restsBetweenSides(int exIdx, SessionSet st) {+ final s = session;+ return s != null &&+ !s.manual &&+ sideRestSeconds > 0 &&+ st.repsR != null &&+ exIdx >= 0 &&+ exIdx < s.exercises.length &&+ isSidedReps(s.exercises[exIdx].id);+ }+void toggleSet(int exIdx, int setIdx) {final st = session!.exercises[exIdx].sets[setIdx];_advanceTimer?.cancel();+ if (!st.done && !st.half && restsBetweenSides(exIdx, st)) {+ st.half = true;+ _persist();+ startRest(seconds: sideRestSeconds, switchSides: true);+ notifyListeners();+ return;+ }+ st.half = false;st.done = !st.done;_persist();notifyListeners();@@ -789,7 +810,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt}final sets = session!.exercises[exIdx].sets;final mini = setIdx + 1 < sets.length && const [SetKind.restPause, SetKind.cluster].contains(sets[setIdx + 1].kind);- startRest(mini: mini, seconds: st.rest);+ startRest(mini: mini, seconds: st.rest ?? (mini ? null : _changeRestAfter(exIdx)));if (autoAdvance || sessionLocked) _advanceWhenDone(exIdx);}@@ -906,9 +927,9 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStnotifyListeners();return;}- startRest();final left = chain.where((i) => s.exercises[i].hasUndone).toList();final next = pendingAfter(chain.last);+ startRest(seconds: left.isEmpty && next != null && changeRestSeconds > 0 ? changeRestSeconds : null);if (left.isNotEmpty) {s.currentIndex = left.first;} else if ((autoAdvance || sessionLocked) && next != null) {@@ -1007,6 +1028,17 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStreturn _beats(ex.id, target.logged, best);}+ int? _changeRestAfter(int exIdx, {int? closing}) {+ final s = session;+ if (s == null || changeRestSeconds <= 0 || exIdx < 0 || exIdx >= s.exercises.length) return null;+ final sets = s.exercises[exIdx].sets;+ for (var i = 0; i < sets.length; i++) {+ if (i != closing && !sets[i].done) return null;+ }+ if (pendingAfter(exIdx) == null) return null;+ return changeRestSeconds;+ }+int normalRestAfter(int exIdx, int setIdx) {final s = session;if (s == null || exIdx < 0 || exIdx >= s.exercises.length) return restSeconds;@@ -1014,6 +1046,8 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStfinal sets = ex.sets;final mini = setIdx + 1 < sets.length && const [SetKind.restPause, SetKind.cluster].contains(sets[setIdx + 1].kind);if (mini && miniRestSeconds > 0) return miniRestSeconds;+ final change = _changeRestAfter(exIdx, closing: setIdx);+ if (change != null) return change;return routineRest(s.routineId, ex.id) ?? restFor(ex.id);}@@ -1027,7 +1061,7 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStnotifyListeners();}- void startRest({bool mini = false, int? seconds}) {+ void startRest({bool mini = false, int? seconds, bool switchSides = false}) {if (sessionPaused || session?.manual == true) return;_restTimer?.cancel();RestAlarm.instance.stopSound();@@ -1045,7 +1079,10 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsStrestTotal = seconds;_armRest(seconds);- if (voiceCoach) {+ session!.restSwitch = switchSides;+ if (voiceCoach && switchSides) {+ VoiceCoach.say(t.switchSides, intlLocale);+ } else if (voiceCoach) {final next = voiceNext();VoiceCoach.say(next == null ? t.voiceRest(voiceDuration(seconds)) : '${t.voiceRest(voiceDuration(seconds))} $next', intlLocale);}@@ -1217,11 +1254,11 @@ mixin WorkoutState on FitCore, SettingsState, LibraryState, PlacesState, StatsSt}void setSessionDistanceShown(int exIdx, int setIdx, double shown) =>- setSessionKm(exIdx, setIdx, fromDisplayKm(shown));+ setSessionKm(exIdx, setIdx, fromDisplayKmFor(session!.exercises[exIdx].id, shown));void bumpSessionDistance(int exIdx, int setIdx, int dir) {final st = session!.exercises[exIdx].sets[setIdx];- final shown = toDisplayKm(st.km ?? 0);+ final shown = toDisplayKmFor(session!.exercises[exIdx].id, st.km ?? 0);final next = ((shown / distanceStep).round() + dir) * distanceStep;setSessionDistanceShown(exIdx, setIdx, next < 0 ? 0 : next);}