diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index 2b62b5a3..061d08a9 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -167,6 +167,14 @@
"dayTypeEdt": "Escalating density training",
"dayTypeRft": "Rounds for time",
"dayTypeAfap": "As fast as possible",
+ "slotEntryTypeNormal": "Normal",
+ "slotEntryTypeDropset": "Dropset",
+ "slotEntryTypeMyo": "Myo",
+ "slotEntryTypePartial": "Partial",
+ "slotEntryTypeForced": "Forced",
+ "slotEntryTypeTut": "Time under Tension",
+ "slotEntryTypeIso": "Isometric hold",
+ "slotEntryTypeJump": "Jump",
"routines": "Routines",
"newRoutine": "New routine",
"noRoutines": "You have no routines",
diff --git a/lib/models/workouts/day.dart b/lib/models/workouts/day.dart
index ed7c1cae..25ed717e 100644
--- a/lib/models/workouts/day.dart
+++ b/lib/models/workouts/day.dart
@@ -16,7 +16,6 @@
* along with this program. If not, see .
*/
-import 'package:flutter/widgets.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/workouts/slot.dart';
@@ -26,9 +25,7 @@ part 'day.g.dart';
enum DayType { custom, enom, amrap, hiit, tabata, edt, rft, afap }
extension DayTypeExtension on DayType {
- String i18Label(BuildContext context) {
- final i18n = AppLocalizations.of(context);
-
+ String i18Label(AppLocalizations i18n) {
switch (this) {
case DayType.custom:
return i18n.dayTypeCustom;
@@ -127,6 +124,8 @@ class Day {
bool get isSpecialType => type != DayType.custom;
+ String typeLabel() => isSpecialType ? '\n(${type.name.toUpperCase()})' : '';
+
// Boilerplate
factory Day.fromJson(Map json) => _$DayFromJson(json);
diff --git a/lib/models/workouts/day.g.dart b/lib/models/workouts/day.g.dart
index 27f17564..8497895c 100644
--- a/lib/models/workouts/day.g.dart
+++ b/lib/models/workouts/day.g.dart
@@ -35,7 +35,7 @@ Day _$DayFromJson(Map json) {
(json['slots'] as List?)
?.map((e) => Slot.fromJson(e as Map))
.toList() ??
- [],
+ const [],
);
}
diff --git a/lib/models/workouts/day_data.g.dart b/lib/models/workouts/day_data.g.dart
index 4744c90b..8fb13e8b 100644
--- a/lib/models/workouts/day_data.g.dart
+++ b/lib/models/workouts/day_data.g.dart
@@ -12,7 +12,9 @@ DayData _$DayDataFromJson(Map json) {
iteration: (json['iteration'] as num).toInt(),
date: DateTime.parse(json['date'] as String),
label: json['label'] as String? ?? '',
- day: json['day'] == null ? null : Day.fromJson(json['day'] as Map),
+ day: json['day'] == null
+ ? null
+ : Day.fromJson(json['day'] as Map),
slots:
(json['slots'] as List?)
?.map((e) => SlotData.fromJson(e as Map))
diff --git a/lib/models/workouts/set_config_data.dart b/lib/models/workouts/set_config_data.dart
index 57d11cda..77893c07 100644
--- a/lib/models/workouts/set_config_data.dart
+++ b/lib/models/workouts/set_config_data.dart
@@ -21,6 +21,7 @@ import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/json.dart';
import 'package:wger/models/exercises/exercise.dart';
import 'package:wger/models/workouts/repetition_unit.dart';
+import 'package:wger/models/workouts/slot_entry.dart';
import 'package:wger/models/workouts/weight_unit.dart';
part 'set_config_data.g.dart';
@@ -37,7 +38,7 @@ class SetConfigData {
late int slotEntryId;
@JsonKey(required: true)
- late String type;
+ late SlotEntryType type;
@JsonKey(required: true, name: 'text_repr')
late String textRepr;
@@ -99,17 +100,17 @@ class SetConfigData {
SetConfigData({
required this.exerciseId,
required this.slotEntryId,
- this.type = 'normal',
+ this.type = SlotEntryType.normal,
required this.nrOfSets,
this.maxNrOfSets,
required this.weight,
this.maxWeight,
this.weightUnitId = WEIGHT_UNIT_KG,
- this.weightRounding = null,
+ this.weightRounding,
required this.repetitions,
this.maxRepetitions,
this.repetitionsUnitId = REP_UNIT_REPETITIONS_ID,
- this.repetitionsRounding = null,
+ this.repetitionsRounding,
required this.rir,
this.maxRir,
required this.rpe,
diff --git a/lib/models/workouts/set_config_data.g.dart b/lib/models/workouts/set_config_data.g.dart
index d2a65835..3e87f7d2 100644
--- a/lib/models/workouts/set_config_data.g.dart
+++ b/lib/models/workouts/set_config_data.g.dart
@@ -29,27 +29,28 @@ SetConfigData _$SetConfigDataFromJson(Map json) {
'rpe',
'rest',
'max_rest',
- 'comment'
+ 'comment',
],
);
return SetConfigData(
exerciseId: (json['exercise'] as num).toInt(),
slotEntryId: (json['slot_entry_id'] as num).toInt(),
- type: json['type'] as String? ?? 'normal',
+ type:
+ $enumDecodeNullable(_$SlotEntryTypeEnumMap, json['type']) ??
+ SlotEntryType.normal,
nrOfSets: json['sets'] as num?,
maxNrOfSets: json['max_sets'] as num?,
weight: stringToNumNull(json['weight'] as String?),
maxWeight: stringToNumNull(json['max_weight'] as String?),
weightUnitId: (json['weight_unit'] as num?)?.toInt() ?? WEIGHT_UNIT_KG,
- weightRounding: json['weight_rounding'] == null
- ? null
- : stringToNumNull(json['weight_rounding'] as String?),
+ weightRounding: stringToNumNull(json['weight_rounding'] as String?),
repetitions: stringToNumNull(json['repetitions'] as String?),
maxRepetitions: stringToNumNull(json['max_repetitions'] as String?),
- repetitionsUnitId: (json['repetitions_unit'] as num?)?.toInt() ?? REP_UNIT_REPETITIONS_ID,
- repetitionsRounding: json['repetitions_rounding'] == null
- ? null
- : stringToNumNull(json['repetitions_rounding'] as String?),
+ repetitionsUnitId:
+ (json['repetitions_unit'] as num?)?.toInt() ?? REP_UNIT_REPETITIONS_ID,
+ repetitionsRounding: stringToNumNull(
+ json['repetitions_rounding'] as String?,
+ ),
rir: stringToNumNull(json['rir'] as String?),
maxRir: stringToNumNull(json['max_rir'] as String?),
rpe: stringToNumNull(json['rpe'] as String?),
@@ -60,10 +61,11 @@ SetConfigData _$SetConfigDataFromJson(Map json) {
);
}
-Map _$SetConfigDataToJson(SetConfigData instance) => {
+Map _$SetConfigDataToJson(SetConfigData instance) =>
+ {
'exercise': instance.exerciseId,
'slot_entry_id': instance.slotEntryId,
- 'type': instance.type,
+ 'type': _$SlotEntryTypeEnumMap[instance.type]!,
'text_repr': instance.textRepr,
'sets': instance.nrOfSets,
'max_sets': instance.maxNrOfSets,
@@ -82,3 +84,14 @@ Map _$SetConfigDataToJson(SetConfigData instance) => json) {
- $checkKeys(json, requiredKeys: const ['comment', 'is_superset', 'exercises', 'sets']);
+ $checkKeys(
+ json,
+ requiredKeys: const ['comment', 'is_superset', 'exercises', 'sets'],
+ );
return SlotData(
comment: json['comment'] as String,
isSuperset: json['is_superset'] as bool,
exerciseIds:
- (json['exercises'] as List?)?.map((e) => (e as num).toInt()).toList() ?? const [],
+ (json['exercises'] as List?)
+ ?.map((e) => (e as num).toInt())
+ .toList() ??
+ const [],
setConfigs:
(json['sets'] as List?)
?.map((e) => SetConfigData.fromJson(e as Map))
diff --git a/lib/models/workouts/slot_entry.dart b/lib/models/workouts/slot_entry.dart
index ef07e966..13fee755 100644
--- a/lib/models/workouts/slot_entry.dart
+++ b/lib/models/workouts/slot_entry.dart
@@ -19,6 +19,7 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/helpers/json.dart';
+import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/exercises/exercise.dart';
import 'package:wger/models/workouts/base_config.dart';
import 'package:wger/models/workouts/repetition_unit.dart';
@@ -28,6 +29,31 @@ part 'slot_entry.g.dart';
enum SlotEntryType { normal, dropset, myo, partial, forced, tut, iso, jump }
+extension SlotEntryTypeExtension on SlotEntryType {
+ String i18Label(AppLocalizations i18n) {
+ switch (this) {
+ case SlotEntryType.normal:
+ return i18n.slotEntryTypeNormal;
+ case SlotEntryType.dropset:
+ return i18n.slotEntryTypeDropset;
+ case SlotEntryType.myo:
+ return i18n.slotEntryTypeMyo;
+ case SlotEntryType.partial:
+ return i18n.slotEntryTypePartial;
+ case SlotEntryType.forced:
+ return i18n.slotEntryTypeForced;
+ case SlotEntryType.tut:
+ return i18n.slotEntryTypeTut;
+ case SlotEntryType.iso:
+ return i18n.slotEntryTypeIso;
+ case SlotEntryType.jump:
+ return i18n.slotEntryTypeJump;
+ }
+ }
+
+ String get typeLabel => this != SlotEntryType.normal ? ' (${name.toUpperCase()})' : '';
+}
+
enum ConfigType {
weight,
maxWeight,
@@ -61,7 +87,7 @@ class SlotEntry {
late String comment;
@JsonKey(required: true)
- late String type;
+ late SlotEntryType type;
@JsonKey(includeFromJson: false, includeToJson: false)
late Exercise exerciseObj;
@@ -123,14 +149,14 @@ class SlotEntry {
SlotEntry({
this.id,
required this.slotId,
- required this.order,
- required this.type,
+ this.order = 1,
+ this.type = SlotEntryType.normal,
required this.exerciseId,
required this.repetitionUnitId,
required this.repetitionRounding,
required this.weightUnitId,
required this.weightRounding,
- required this.comment,
+ this.comment = '',
this.weightConfigs = const [],
this.maxWeightConfigs = const [],
this.nrOfSetsConfigs = const [],
@@ -162,7 +188,7 @@ class SlotEntry {
required this.slotId,
String? comment,
int? order,
- String? type,
+ SlotEntryType? type,
required Exercise exercise,
int? weightUnitId,
this.weightRounding,
@@ -172,7 +198,7 @@ class SlotEntry {
this.order = order ?? 1;
this.comment = comment ?? '';
config = null;
- this.type = type ?? 'normal';
+ this.type = type ?? SlotEntryType.normal;
exerciseObj = exercise;
exerciseId = exercise.id!;
this.weightUnitId = weightUnitId ?? WEIGHT_UNIT_KG;
diff --git a/lib/models/workouts/slot_entry.g.dart b/lib/models/workouts/slot_entry.g.dart
index 5de52481..0cc2848c 100644
--- a/lib/models/workouts/slot_entry.g.dart
+++ b/lib/models/workouts/slot_entry.g.dart
@@ -26,14 +26,16 @@ SlotEntry _$SlotEntryFromJson(Map json) {
return SlotEntry(
id: (json['id'] as num?)?.toInt(),
slotId: (json['slot'] as num).toInt(),
- order: (json['order'] as num).toInt(),
- type: json['type'] as String,
+ order: (json['order'] as num?)?.toInt() ?? 1,
+ type:
+ $enumDecodeNullable(_$SlotEntryTypeEnumMap, json['type']) ??
+ SlotEntryType.normal,
exerciseId: (json['exercise'] as num).toInt(),
repetitionUnitId: (json['repetition_unit'] as num?)?.toInt(),
repetitionRounding: stringToNumNull(json['repetition_rounding'] as String?),
weightUnitId: (json['weight_unit'] as num?)?.toInt(),
weightRounding: stringToNumNull(json['weight_rounding'] as String?),
- comment: json['comment'] as String,
+ comment: json['comment'] as String? ?? '',
weightConfigs:
(json['weight_configs'] as List?)
?.map((e) => BaseConfig.fromJson(e as Map))
@@ -91,7 +93,7 @@ Map _$SlotEntryToJson(SlotEntry instance) => {
'slot': instance.slotId,
'order': instance.order,
'comment': instance.comment,
- 'type': instance.type,
+ 'type': _$SlotEntryTypeEnumMap[instance.type]!,
'exercise': instance.exerciseId,
'repetition_unit': instance.repetitionUnitId,
'repetition_rounding': instance.repetitionRounding,
@@ -99,3 +101,14 @@ Map _$SlotEntryToJson(SlotEntry instance) => {
'weight_rounding': instance.weightRounding,
'config': instance.config,
};
+
+const _$SlotEntryTypeEnumMap = {
+ SlotEntryType.normal: 'normal',
+ SlotEntryType.dropset: 'dropset',
+ SlotEntryType.myo: 'myo',
+ SlotEntryType.partial: 'partial',
+ SlotEntryType.forced: 'forced',
+ SlotEntryType.tut: 'tut',
+ SlotEntryType.iso: 'iso',
+ SlotEntryType.jump: 'jump',
+};
diff --git a/lib/models/workouts/weight_unit.g.dart b/lib/models/workouts/weight_unit.g.dart
index ba89171d..7caef784 100644
--- a/lib/models/workouts/weight_unit.g.dart
+++ b/lib/models/workouts/weight_unit.g.dart
@@ -7,17 +7,11 @@ part of 'weight_unit.dart';
// **************************************************************************
WeightUnit _$WeightUnitFromJson(Map json) {
- $checkKeys(
- json,
- requiredKeys: const ['id', 'name'],
- );
- return WeightUnit(
- id: (json['id'] as num).toInt(),
- name: json['name'] as String,
- );
+ $checkKeys(json, requiredKeys: const ['id', 'name']);
+ return WeightUnit(id: (json['id'] as num).toInt(), name: json['name'] as String);
}
Map _$WeightUnitToJson(WeightUnit instance) => {
- 'id': instance.id,
- 'name': instance.name,
- };
+ 'id': instance.id,
+ 'name': instance.name,
+};
diff --git a/lib/widgets/routines/day.dart b/lib/widgets/routines/day.dart
index 875f6a92..f4820ac5 100644
--- a/lib/widgets/routines/day.dart
+++ b/lib/widgets/routines/day.dart
@@ -22,6 +22,7 @@ import 'package:wger/l10n/generated/app_localizations.dart';
import 'package:wger/models/exercises/exercise.dart';
import 'package:wger/models/workouts/day_data.dart';
import 'package:wger/models/workouts/slot_data.dart';
+import 'package:wger/models/workouts/slot_entry.dart';
import 'package:wger/screens/gym_mode.dart';
import 'package:wger/widgets/core/core.dart';
import 'package:wger/widgets/exercises/exercises.dart';
@@ -82,7 +83,9 @@ class RoutineDayWidget extends StatelessWidget {
// the one exercise and don't show separate rows for each one.
...slotData.setConfigs
.fold