This commit is contained in:
@ -115,6 +115,17 @@ class MediaNotifier extends StateNotifier<MediaState> {
|
||||
}
|
||||
}
|
||||
|
||||
List<MediaItem> mergeMediaItems(
|
||||
List<MediaItem> current,
|
||||
List<MediaItem> incoming,
|
||||
) {
|
||||
final existingIds = current.map((item) => item.id).toSet();
|
||||
final newItems = incoming
|
||||
.where((item) => !existingIds.contains(item.id))
|
||||
.toList();
|
||||
return [...current, ...newItems];
|
||||
}
|
||||
|
||||
Future<void> loadMedia({int? id}) async {
|
||||
if (state.isLoading) return;
|
||||
state = state.replace(isLoading: true);
|
||||
@ -128,8 +139,11 @@ class MediaNotifier extends StateNotifier<MediaState> {
|
||||
random: state.random,
|
||||
tag: state.tag,
|
||||
);
|
||||
|
||||
if (newMedia.isNotEmpty) {
|
||||
addMediaItems(newMedia);
|
||||
state = state.replace(
|
||||
mediaItems: mergeMediaItems(state.mediaItems, newMedia),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Fehler beim Laden der Medien: $e');
|
||||
|
Reference in New Issue
Block a user