Offline gym log for Android. No account, no ads, no internet.
Dart androidbodybuildingdartexercisesf-droidfitnessfluttergymgym-apphealthprivacyself-hostedworkoutworkout-appworkout-tracker
Add cluster sets, cardio details and saved plans to the models
InlitXe77ff0f62796
diff --git a/lib/models/workout.dart b/lib/models/workout.dartindex 4356e66..7e5c280 100644--- a/lib/models/workout.dart+++ b/lib/models/workout.dart@@ -1,4 +1,4 @@-enum SetKind { normal, warmup, drop, failure, restPause }+enum SetKind { normal, warmup, drop, failure, restPause, cluster }SetKind setKindFrom(Object? raw) {final i = (raw as num?)?.toInt() ?? 0;@@ -69,11 +69,13 @@ enum PrKind {typedef PersonalRecord = ({String id, String name, PrKind kind, double best, double oneRm});class LoggedExercise {- LoggedExercise(this.id, this.name, this.primary, this.sets);+ LoggedExercise(this.id, this.name, this.primary, this.sets, {this.incline, this.kcal});final String id;final String name;final String primary;final List<LoggedSet> sets;+ double? incline;+ int? kcal;List<LoggedSet> get workingSets => sets.where((s) => s.counts).toList();@@ -93,12 +95,16 @@ class LoggedExercise {'n': name,'p': primary,'s': sets.map((s) => s.toJson()).toList(),+ if (incline != null) 'g': incline,+ if (kcal != null) 'kc': kcal,};factory LoggedExercise.fromJson(Map<String, dynamic> j) => LoggedExercise(j['id'] as String,j['n'] as String,j['p'] as String,(j['s'] as List).map((e) => LoggedSet.fromJson(e as Map<String, dynamic>)).toList(),+ incline: (j['g'] as num?)?.toDouble(),+ kcal: (j['kc'] as num?)?.toInt(),);}@@ -180,6 +186,45 @@ class PlannedSet {);}+class SavedPlan {+ SavedPlan(this.id, this.name, this.week, this.extras, {this.multi = false});+ final String id;+ String name;+ final Map<int, String> week;+ final Map<int, List<String>> extras;+ final bool multi;++ bool uses(String routineId) => week.containsValue(routineId) || extras.values.any((ids) => ids.contains(routineId));++ void drop(String routineId) {+ week.removeWhere((_, v) => v == routineId);+ for (final ids in extras.values) {+ ids.remove(routineId);+ }+ for (final day in [...extras.keys]) {+ final ids = extras[day]!;+ if (week[day] == null && ids.isNotEmpty) week[day] = ids.removeAt(0);+ if (ids.isEmpty) extras.remove(day);+ }+ }++ Map<String, dynamic> toJson() => {+ 'id': id,+ 'n': name,+ 'w': week.map((k, v) => MapEntry('$k', v)),+ if (extras.isNotEmpty) 'x': extras.map((k, v) => MapEntry('$k', v)),+ if (multi) 'm': true,+ };+ factory SavedPlan.fromJson(Map<String, dynamic> j) => SavedPlan(+ j['id'] as String,+ j['n'] as String? ?? '',+ ((j['w'] as Map?) ?? const {}).map((k, v) => MapEntry(int.parse(k as String), v as String)),+ ((j['x'] as Map?) ?? const {})+ .map((k, v) => MapEntry(int.parse(k as String), (v as List).cast<String>().toList())),+ multi: j['m'] as bool? ?? false,+ );+}+class Routine {Routine(this.id, this.name, this.exerciseIds,{Map<String, int>? sets,