Add workaround for #722

This commit is contained in:
Roland Geider
2025-01-22 19:29:17 +01:00
parent f77fbcaf3e
commit eac2397396
3 changed files with 23 additions and 5 deletions

View File

@@ -16,6 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:developer';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/helpers/consts.dart';
@@ -160,7 +162,15 @@ class Exercise extends Equatable {
equipment = baseData.equipment;
category = baseData.category;
translations = baseData.translations.map((e) {
e.language = languages.firstWhere((l) => l.id == e.languageId);
e.language = languages.firstWhere(
(l) => l.id == e.languageId,
// workaround for https://github.com/wger-project/flutter/issues/722
orElse: () {
log('Could not find language for translation ${e.languageId}');
return Language(id: e.languageId, shortName: 'unknown', fullName: 'unknown');
},
);
return e;
}).toList();
videos = baseData.videos;

View File

@@ -298,9 +298,17 @@ class ExercisesProvider with ChangeNotifier {
int exerciseId,
) async {
Exercise exercise;
final exerciseDb = await (database.select(database.exercises)
..where((e) => e.id.equals(exerciseId)))
.getSingleOrNull();
// TODO: this should be a .getSingleOrNull()!!! However, for some reason there
// can be duplicates in the db. Perhaps a race condition so that two
// entries are written at the same time or something?
final exerciseResult =
await (database.select(database.exercises)..where((e) => e.id.equals(exerciseId))).get();
ExerciseTable? exerciseDb;
if (exerciseResult.isNotEmpty) {
exerciseDb = exerciseResult.first;
}
// Exercise is already known locally
if (exerciseDb != null) {

View File

@@ -1576,4 +1576,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.6.0 <4.0.0"
flutter: ">=3.24.0"
flutter: ">=3.27.0"