From 72deeda4f7edcabded4c5ac1b778277b0601d8ab Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 4 Nov 2025 16:15:37 +0100 Subject: [PATCH] Update session and log models --- lib/models/workouts/session.dart | 2 +- lib/models/workouts/session.g.dart | 24 ++------- lib/providers/body_weight.g.dart | 18 ------- lib/providers/network_provider.g.dart | 18 ------- lib/widgets/routines/gym_mode/log_page.dart | 56 ++++++++------------- 5 files changed, 26 insertions(+), 92 deletions(-) diff --git a/lib/models/workouts/session.dart b/lib/models/workouts/session.dart index 45e02535..c54fb870 100644 --- a/lib/models/workouts/session.dart +++ b/lib/models/workouts/session.dart @@ -29,7 +29,7 @@ const IMPRESSION_MAP = {1: 'bad', 2: 'neutral', 3: 'good'}; @JsonSerializable() class WorkoutSession { - @JsonKey(required: true) + @JsonKey(required: true, name: 'uuid') String? id; @JsonKey(required: true, name: 'routine') diff --git a/lib/models/workouts/session.g.dart b/lib/models/workouts/session.g.dart index 4f8b5285..7b5fd97d 100644 --- a/lib/models/workouts/session.g.dart +++ b/lib/models/workouts/session.g.dart @@ -1,21 +1,3 @@ -/* - * This file is part of wger Workout Manager . - * Copyright (c) 2020, wger Team - * - * wger Workout Manager is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - // GENERATED CODE - DO NOT MODIFY BY HAND part of 'session.dart'; @@ -28,7 +10,7 @@ WorkoutSession _$WorkoutSessionFromJson(Map json) { $checkKeys( json, requiredKeys: const [ - 'id', + 'uuid', 'routine', 'day', 'date', @@ -38,7 +20,7 @@ WorkoutSession _$WorkoutSessionFromJson(Map json) { ], ); return WorkoutSession( - id: json['id'] as String?, + id: json['uuid'] as String?, dayId: (json['day'] as num?)?.toInt(), routineId: (json['routine'] as num?)?.toInt(), impression: json['impression'] == null ? 2 : int.parse(json['impression'] as String), @@ -55,7 +37,7 @@ WorkoutSession _$WorkoutSessionFromJson(Map json) { } Map _$WorkoutSessionToJson(WorkoutSession instance) => { - 'id': instance.id, + 'uuid': instance.id, 'routine': instance.routineId, 'day': instance.dayId, 'date': dateToYYYYMMDD(instance.date), diff --git a/lib/providers/body_weight.g.dart b/lib/providers/body_weight.g.dart index d44bf6e9..3f0098a4 100644 --- a/lib/providers/body_weight.g.dart +++ b/lib/providers/body_weight.g.dart @@ -1,21 +1,3 @@ -/* - * This file is part of wger Workout Manager . - * Copyright (c) 2020, wger Team - * - * wger Workout Manager is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - // GENERATED CODE - DO NOT MODIFY BY HAND part of 'body_weight.dart'; diff --git a/lib/providers/network_provider.g.dart b/lib/providers/network_provider.g.dart index 1d3dda4b..c59fd43f 100644 --- a/lib/providers/network_provider.g.dart +++ b/lib/providers/network_provider.g.dart @@ -1,21 +1,3 @@ -/* - * This file is part of wger Workout Manager . - * Copyright (c) 2020, wger Team - * - * wger Workout Manager is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - // GENERATED CODE - DO NOT MODIFY BY HAND part of 'network_provider.dart'; diff --git a/lib/widgets/routines/gym_mode/log_page.dart b/lib/widgets/routines/gym_mode/log_page.dart index 899d82ea..2c446a2d 100644 --- a/lib/widgets/routines/gym_mode/log_page.dart +++ b/lib/widgets/routines/gym_mode/log_page.dart @@ -19,8 +19,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:logging/logging.dart'; -import 'package:provider/provider.dart' as provider; -import 'package:wger/exceptions/http_exception.dart'; import 'package:wger/helpers/consts.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; import 'package:wger/models/exercises/exercise.dart'; @@ -30,7 +28,7 @@ import 'package:wger/models/workouts/set_config_data.dart'; import 'package:wger/models/workouts/slot_data.dart'; import 'package:wger/models/workouts/slot_entry.dart'; import 'package:wger/providers/plate_weights.dart'; -import 'package:wger/providers/routines.dart'; +import 'package:wger/providers/workout_logs.dart'; import 'package:wger/screens/configure_plates_screen.dart'; import 'package:wger/widgets/core/core.dart'; import 'package:wger/widgets/core/progress_indicator.dart'; @@ -540,6 +538,7 @@ class _LogFormWidgetState extends ConsumerState { @override Widget build(BuildContext context) { final i18n = AppLocalizations.of(context); + final logProvider = ref.watch(workoutLogProvider.notifier); return Form( key: _form, @@ -655,43 +654,32 @@ class _LogFormWidgetState extends ConsumerState { if (!isValid) { return; } - _isSaving = true; + setState(() { + _isSaving = true; + }); _form.currentState!.save(); - try { - await provider.Provider.of( - context, - listen: false, - ).addLog(widget.log); + widget.log.id = null; + logProvider.addEntry(widget.log); - if (mounted) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 2), - content: Text( - i18n.successfullySaved, - textAlign: TextAlign.center, - ), + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 2), + content: Text( + i18n.successfullySaved, + textAlign: TextAlign.center, ), - ); - } - widget.controller.nextPage( - duration: DEFAULT_ANIMATION_DURATION, - curve: DEFAULT_ANIMATION_CURVE, + ), ); - setState(() { - _isSaving = false; - }); - } on WgerHttpException { - setState(() { - _isSaving = false; - }); - rethrow; - } finally { - setState(() { - _isSaving = false; - }); } + widget.controller.nextPage( + duration: DEFAULT_ANIMATION_DURATION, + curve: DEFAULT_ANIMATION_CURVE, + ); + setState(() { + _isSaving = false; + }); }, child: _isSaving ? const FormProgressIndicator() : Text(i18n.save), ),