mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Also read max sets and mar rir from the API
This commit is contained in:
@@ -26,11 +26,11 @@ Day _$DayFromJson(Map<String, dynamic> 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<dynamic>?)
|
||||
?.map((e) => Slot.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
|
||||
@@ -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<String, dynamic> json) => _$SetConfigDataFromJson(json);
|
||||
|
||||
@@ -15,6 +15,7 @@ SetConfigData _$SetConfigDataFromJson(Map<String, dynamic> json) {
|
||||
'type',
|
||||
'text_repr',
|
||||
'sets',
|
||||
'max_sets',
|
||||
'weight',
|
||||
'max_weight',
|
||||
'weight_unit',
|
||||
@@ -24,6 +25,7 @@ SetConfigData _$SetConfigDataFromJson(Map<String, dynamic> json) {
|
||||
'reps_unit',
|
||||
'reps_rounding',
|
||||
'rir',
|
||||
'max_rir',
|
||||
'rpe',
|
||||
'rest',
|
||||
'max_rest',
|
||||
@@ -33,23 +35,28 @@ SetConfigData _$SetConfigDataFromJson(Map<String, dynamic> 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<String, dynamic> _$SetConfigDataToJson(SetConfigData instance) => <String, dynamic>{
|
||||
@@ -58,6 +65,7 @@ Map<String, dynamic> _$SetConfigDataToJson(SetConfigData instance) => <String, d
|
||||
'type': instance.type,
|
||||
'text_repr': instance.textRepr,
|
||||
'sets': instance.nrOfSets,
|
||||
'max_sets': instance.maxNrOfSets,
|
||||
'weight': instance.weight,
|
||||
'max_weight': instance.maxWeight,
|
||||
'weight_unit': instance.weightUnitId,
|
||||
@@ -67,6 +75,7 @@ Map<String, dynamic> _$SetConfigDataToJson(SetConfigData instance) => <String, d
|
||||
'reps_unit': instance.repsUnitId,
|
||||
'reps_rounding': instance.repsRounding,
|
||||
'rir': instance.rir,
|
||||
'max_rir': instance.maxRir,
|
||||
'rpe': instance.rpe,
|
||||
'rest': instance.restTime,
|
||||
'max_rest': instance.maxRestTime,
|
||||
|
||||
Reference in New Issue
Block a user