mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Add workaround for #722
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user