diff --git a/lib/models/workouts/day.g.dart b/lib/models/workouts/day.g.dart index 5bc8f7fd..000f7331 100644 --- a/lib/models/workouts/day.g.dart +++ b/lib/models/workouts/day.g.dart @@ -26,11 +26,11 @@ Day _$DayFromJson(Map json) { routineId: (json['routine'] as num).toInt(), name: json['name'] as String, description: json['description'] as String, - isRest: json['is_rest'] as bool, - needLogsToAdvance: json['need_logs_to_advance'] as bool, - type: json['type'] as String, - order: json['order'] as num, - config: json['config'], + isRest: json['is_rest'] as bool? ?? false, + needLogsToAdvance: json['need_logs_to_advance'] as bool? ?? false, + type: json['type'] as String? ?? 'custom', + order: json['order'] as num? ?? 0, + config: json['config'] ?? null, slots: (json['slots'] as List?) ?.map((e) => Slot.fromJson(e as Map)) .toList() ?? diff --git a/lib/models/workouts/set_config_data.dart b/lib/models/workouts/set_config_data.dart index a3cb50ff..f096209a 100644 --- a/lib/models/workouts/set_config_data.dart +++ b/lib/models/workouts/set_config_data.dart @@ -17,6 +17,7 @@ */ import 'package:json_annotation/json_annotation.dart'; +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'; @@ -44,6 +45,9 @@ class SetConfigData { @JsonKey(required: true, name: 'sets') late num? nrOfSets; + @JsonKey(required: true, name: 'max_sets') + late num? maxNrOfSets; + @JsonKey(required: true, fromJson: stringToNumNull) late num? weight; @@ -77,6 +81,9 @@ class SetConfigData { @JsonKey(required: true) late String? rir; + @JsonKey(required: true, name: 'max_rir') + late String? maxRir; + @JsonKey(required: true) late String? rpe; @@ -92,20 +99,38 @@ class SetConfigData { SetConfigData({ required this.exerciseId, required this.slotEntryId, - required this.type, + this.type = 'normal', + required this.nrOfSets, + this.maxNrOfSets, required this.weight, - required this.weightUnitId, - required this.weightRounding, + this.maxWeight, + this.weightUnitId = WEIGHT_UNIT_KG, + this.weightRounding = 1.25, required this.reps, - required this.maxReps, - required this.repsUnitId, - required this.repsRounding, + this.maxReps, + this.repsUnitId = REP_UNIT_REPETITIONS_ID, + this.repsRounding = 1, required this.rir, + this.maxRir, required this.rpe, required this.restTime, - required this.maxRestTime, - required this.comment, - }); + this.maxRestTime, + this.comment = '', + this.textRepr = '', + Exercise? exercise, + WeightUnit? weightUnit, + RepetitionUnit? repsUnit, + }) { + if (exercise != null) { + this.exercise = exercise; + } + if (weightUnit != null) { + this.weightUnit = weightUnit; + } + if (repsUnit != null) { + this.repsUnit = repsUnit; + } + } // Boilerplate factory SetConfigData.fromJson(Map json) => _$SetConfigDataFromJson(json); diff --git a/lib/models/workouts/set_config_data.g.dart b/lib/models/workouts/set_config_data.g.dart index 3e048776..962a3775 100644 --- a/lib/models/workouts/set_config_data.g.dart +++ b/lib/models/workouts/set_config_data.g.dart @@ -15,6 +15,7 @@ SetConfigData _$SetConfigDataFromJson(Map json) { 'type', 'text_repr', 'sets', + 'max_sets', 'weight', 'max_weight', 'weight_unit', @@ -24,6 +25,7 @@ SetConfigData _$SetConfigDataFromJson(Map json) { 'reps_unit', 'reps_rounding', 'rir', + 'max_rir', 'rpe', 'rest', 'max_rest', @@ -33,23 +35,28 @@ SetConfigData _$SetConfigDataFromJson(Map json) { return SetConfigData( exerciseId: (json['exercise'] as num).toInt(), slotEntryId: (json['slot_entry_id'] as num).toInt(), - type: json['type'] as String, + type: json['type'] as String? ?? 'normal', + nrOfSets: json['sets'] as num?, + maxNrOfSets: json['max_sets'] as num?, weight: stringToNumNull(json['weight'] as String?), - weightUnitId: (json['weight_unit'] as num?)?.toInt(), - weightRounding: stringToNumNull(json['weight_rounding'] as String?), + maxWeight: stringToNumNull(json['max_weight'] as String?), + weightUnitId: (json['weight_unit'] as num?)?.toInt() ?? WEIGHT_UNIT_KG, + weightRounding: json['weight_rounding'] == null + ? 1.25 + : stringToNumNull(json['weight_rounding'] as String?), reps: stringToNumNull(json['reps'] as String?), maxReps: stringToNumNull(json['max_reps'] as String?), - repsUnitId: (json['reps_unit'] as num?)?.toInt(), - repsRounding: stringToNumNull(json['reps_rounding'] as String?), + repsUnitId: (json['reps_unit'] as num?)?.toInt() ?? REP_UNIT_REPETITIONS_ID, + repsRounding: + json['reps_rounding'] == null ? 1 : stringToNumNull(json['reps_rounding'] as String?), rir: json['rir'] as String?, + maxRir: json['max_rir'] as String?, rpe: json['rpe'] as String?, restTime: stringToNum(json['rest'] as String?), maxRestTime: stringToNum(json['max_rest'] as String?), - comment: json['comment'] as String, - ) - ..textRepr = json['text_repr'] as String - ..nrOfSets = json['sets'] as num? - ..maxWeight = stringToNumNull(json['max_weight'] as String?); + comment: json['comment'] as String? ?? '', + textRepr: json['text_repr'] as String? ?? '', + ); } Map _$SetConfigDataToJson(SetConfigData instance) => { @@ -58,6 +65,7 @@ Map _$SetConfigDataToJson(SetConfigData instance) => _$SetConfigDataToJson(SetConfigData instance) =>