mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Make the repetition and weight units nullable as per the backend
This commit is contained in:
@@ -25,9 +25,9 @@ import 'package:wger/models/workouts/weight_unit.dart';
|
||||
/// Returns the text representation for a single setting, used in the gym mode
|
||||
String repText(
|
||||
num? repetitions,
|
||||
RepetitionUnit repetitionUnitObj,
|
||||
RepetitionUnit? repetitionUnitObj,
|
||||
num? weight,
|
||||
WeightUnit weightUnitObj,
|
||||
WeightUnit? weightUnitObj,
|
||||
String? rir,
|
||||
) {
|
||||
// TODO(x): how to (easily?) translate strings like the units or 'RiR'
|
||||
@@ -42,15 +42,17 @@ String repText(
|
||||
// rather "8 repetitions". If there is weight we want to output "8 x 50kg",
|
||||
// since the repetitions are implied. If other units are used, we always
|
||||
// print them
|
||||
if (repetitionUnitObj.id != REP_UNIT_REPETITIONS_ID || weight == 0 || weight == null) {
|
||||
out.add(repetitionUnitObj.name);
|
||||
if (repetitionUnitObj != null && repetitionUnitObj.id != REP_UNIT_REPETITIONS_ID ||
|
||||
weight == 0 ||
|
||||
weight == null) {
|
||||
out.add(repetitionUnitObj!.name);
|
||||
}
|
||||
}
|
||||
|
||||
if (weight != null && weight != 0) {
|
||||
out.add('×');
|
||||
out.add(formatNum(weight).toString());
|
||||
out.add(weightUnitObj.name);
|
||||
out.add(weightUnitObj!.name);
|
||||
}
|
||||
|
||||
if (rir != null && rir != '') {
|
||||
|
||||
@@ -62,10 +62,10 @@ class Log {
|
||||
num? repetitionsTarget;
|
||||
|
||||
@JsonKey(required: true, name: 'repetitions_unit')
|
||||
late int repetitionsUnitId;
|
||||
late int? repetitionsUnitId;
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
late RepetitionUnit repetitionsUnitObj;
|
||||
late RepetitionUnit? repetitionsUnitObj;
|
||||
|
||||
@JsonKey(required: true, fromJson: stringToNum, toJson: numToString)
|
||||
late num? weight;
|
||||
@@ -74,10 +74,10 @@ class Log {
|
||||
num? weightTarget;
|
||||
|
||||
@JsonKey(required: true, name: 'weight_unit')
|
||||
late int weightUnitId;
|
||||
late int? weightUnitId;
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
late WeightUnit weightUnitObj;
|
||||
late WeightUnit? weightUnitObj;
|
||||
|
||||
@JsonKey(required: true, toJson: dateToYYYYMMDD)
|
||||
late DateTime date;
|
||||
@@ -111,14 +111,14 @@ class Log {
|
||||
exerciseId = base.id!;
|
||||
}
|
||||
|
||||
set weightUnit(WeightUnit weightUnit) {
|
||||
set weightUnit(WeightUnit? weightUnit) {
|
||||
weightUnitObj = weightUnit;
|
||||
weightUnitId = weightUnit.id;
|
||||
weightUnitId = weightUnit?.id;
|
||||
}
|
||||
|
||||
set repetitionUnit(RepetitionUnit repetitionUnit) {
|
||||
set repetitionUnit(RepetitionUnit? repetitionUnit) {
|
||||
repetitionsUnitObj = repetitionUnit;
|
||||
repetitionsUnitId = repetitionUnit.id;
|
||||
repetitionsUnitId = repetitionUnit?.id;
|
||||
}
|
||||
|
||||
void setRir(String rir) {
|
||||
|
||||
@@ -58,7 +58,7 @@ class SetConfigData {
|
||||
late int? weightUnitId;
|
||||
|
||||
@JsonKey(includeToJson: false, includeFromJson: false)
|
||||
late WeightUnit weightUnit;
|
||||
late WeightUnit? weightUnit;
|
||||
|
||||
@JsonKey(required: true, name: 'weight_rounding', fromJson: stringToNumNull)
|
||||
late num? weightRounding;
|
||||
@@ -73,7 +73,7 @@ class SetConfigData {
|
||||
late int? repetitionsUnitId;
|
||||
|
||||
@JsonKey(includeToJson: false, includeFromJson: false)
|
||||
late RepetitionUnit repetitionsUnit;
|
||||
late RepetitionUnit? repetitionsUnit;
|
||||
|
||||
@JsonKey(required: true, name: 'repetitions_rounding', fromJson: stringToNumNull)
|
||||
late num? repetitionsRounding;
|
||||
|
||||
@@ -68,10 +68,10 @@ class SlotEntry {
|
||||
late int exerciseId;
|
||||
|
||||
@JsonKey(required: true, name: 'repetition_unit')
|
||||
late int repetitionUnitId;
|
||||
late int? repetitionUnitId;
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
late RepetitionUnit repetitionUnitObj;
|
||||
late RepetitionUnit? repetitionUnitObj;
|
||||
|
||||
@JsonKey(required: true, name: 'repetition_rounding', fromJson: stringToNum)
|
||||
late num repetitionRounding;
|
||||
@@ -83,10 +83,10 @@ class SlotEntry {
|
||||
late List<BaseConfig> maxRepetitionsConfigs = [];
|
||||
|
||||
@JsonKey(required: true, name: 'weight_unit')
|
||||
late int weightUnitId;
|
||||
late int? weightUnitId;
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
late WeightUnit weightUnitObj;
|
||||
late WeightUnit? weightUnitObj;
|
||||
|
||||
@JsonKey(required: true, name: 'weight_rounding', fromJson: stringToNum)
|
||||
late num weightRounding;
|
||||
|
||||
@@ -29,9 +29,9 @@ SlotEntry _$SlotEntryFromJson(Map<String, dynamic> json) {
|
||||
order: (json['order'] as num).toInt(),
|
||||
type: json['type'] as String,
|
||||
exerciseId: (json['exercise'] as num).toInt(),
|
||||
repetitionUnitId: (json['repetition_unit'] as num).toInt(),
|
||||
repetitionUnitId: (json['repetition_unit'] as num?)?.toInt(),
|
||||
repetitionRounding: stringToNum(json['repetition_rounding'] as String?),
|
||||
weightUnitId: (json['weight_unit'] as num).toInt(),
|
||||
weightUnitId: (json['weight_unit'] as num?)?.toInt(),
|
||||
weightRounding: stringToNum(json['weight_rounding'] as String?),
|
||||
comment: json['comment'] as String,
|
||||
weightConfigs: (json['weight_configs'] as List<dynamic>?)
|
||||
|
||||
@@ -26,12 +26,11 @@ import 'package:wger/providers/routines.dart';
|
||||
///
|
||||
/// Can be used with a Setting or a Log object
|
||||
class RepetitionUnitInputWidget extends StatefulWidget {
|
||||
final int _initialValue;
|
||||
late int selectedRepetitionUnit;
|
||||
final ValueChanged<int> onChanged;
|
||||
late int? selectedRepetitionUnit;
|
||||
final ValueChanged<int?> onChanged;
|
||||
|
||||
RepetitionUnitInputWidget(this._initialValue, {required this.onChanged}) {
|
||||
selectedRepetitionUnit = _initialValue;
|
||||
RepetitionUnitInputWidget(initialValue, {required this.onChanged}) {
|
||||
selectedRepetitionUnit = initialValue;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -43,7 +42,9 @@ class _RepetitionUnitInputWidgetState extends State<RepetitionUnitInputWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
final unitProvider = context.read<RoutinesProvider>();
|
||||
|
||||
RepetitionUnit selectedWeightUnit = unitProvider.findRepetitionUnitById(widget._initialValue);
|
||||
RepetitionUnit? selectedWeightUnit = widget.selectedRepetitionUnit != null
|
||||
? unitProvider.findRepetitionUnitById(widget.selectedRepetitionUnit!)
|
||||
: null;
|
||||
|
||||
return DropdownButtonFormField(
|
||||
value: selectedWeightUnit,
|
||||
|
||||
@@ -26,12 +26,11 @@ import 'package:wger/providers/routines.dart';
|
||||
///
|
||||
/// Can be used with a Setting or a Log object
|
||||
class WeightUnitInputWidget extends StatefulWidget {
|
||||
final int _initialValue;
|
||||
late int selectedWeightUnit;
|
||||
final ValueChanged<int> onChanged;
|
||||
late int? selectedWeightUnit;
|
||||
final ValueChanged<int?> onChanged;
|
||||
|
||||
WeightUnitInputWidget(this._initialValue, {required this.onChanged}) {
|
||||
selectedWeightUnit = _initialValue;
|
||||
WeightUnitInputWidget(initialValue, {required this.onChanged}) {
|
||||
selectedWeightUnit = initialValue;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -43,7 +42,9 @@ class _WeightUnitInputWidgetState extends State<WeightUnitInputWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
final unitProvider = context.read<RoutinesProvider>();
|
||||
|
||||
WeightUnit selectedWeightUnit = unitProvider.findWeightUnitById(widget._initialValue);
|
||||
WeightUnit? selectedWeightUnit = widget.selectedWeightUnit != null
|
||||
? unitProvider.findWeightUnitById(widget.selectedWeightUnit!)
|
||||
: null;
|
||||
|
||||
return DropdownButtonFormField(
|
||||
value: selectedWeightUnit,
|
||||
|
||||
@@ -37,7 +37,7 @@ void main() {
|
||||
const unit2 = RepetitionUnit(id: 2, name: 'another name');
|
||||
const unit3 = RepetitionUnit(id: 3, name: 'this is repetition number 3');
|
||||
|
||||
var result = -1;
|
||||
int? result;
|
||||
|
||||
final slotEntry = SlotEntry(
|
||||
slotId: 1,
|
||||
@@ -54,7 +54,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
mockWorkoutPlans = MockRoutinesProvider();
|
||||
result = -1;
|
||||
result = null;
|
||||
when(mockWorkoutPlans.repetitionUnits).thenAnswer((_) => [unit1, unit2, unit3]);
|
||||
when(mockWorkoutPlans.findRepetitionUnitById(1)).thenReturn(unit1);
|
||||
when(mockWorkoutPlans.findRepetitionUnitById(2)).thenReturn(unit2);
|
||||
|
||||
@@ -33,7 +33,7 @@ import 'weight_unit_form_widget_test.mocks.dart';
|
||||
@GenerateMocks([RoutinesProvider])
|
||||
void main() {
|
||||
var mockWorkoutPlans = MockRoutinesProvider();
|
||||
var result = -1;
|
||||
int? result;
|
||||
|
||||
const unit1 = WeightUnit(id: 1, name: 'kg');
|
||||
const unit2 = WeightUnit(id: 2, name: 'donkeys');
|
||||
@@ -53,7 +53,7 @@ void main() {
|
||||
slotEntry.weightUnitObj = unit1;
|
||||
|
||||
setUp(() {
|
||||
result = -1;
|
||||
result = null;
|
||||
mockWorkoutPlans = MockRoutinesProvider();
|
||||
when(mockWorkoutPlans.weightUnits).thenAnswer((_) => [unit1, unit2, unit3]);
|
||||
when(mockWorkoutPlans.findWeightUnitById(1)).thenReturn(unit1);
|
||||
|
||||
Reference in New Issue
Block a user