Fixed missing loading spinner due to seeded streams in note repository.

This commit is contained in:
Dennis Nemec
2026-01-08 15:59:45 +01:00
parent 6eafb0fab0
commit b481a45afc
4 changed files with 63 additions and 58 deletions

View File

@ -26,19 +26,27 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
required this.deliveryId,
}) : super(NoteInitial()) {
_combinedSubscription = CombineLatestStream.combine3(
repository.notes,
repository.images,
repository.templates,
(note, image, templates) => {"note": note, "image": image, "templates": templates},
).listen(
(data) => add(
DataUpdated(
images: data["image"] as List<ImageNote>,
notes: data["note"] as List<Note>,
templates: data["templates"] as List<NoteTemplate>
),
),
);
repository.notes,
repository.images,
repository.templates,
(note, image, templates) {
if (note == null || image == null || templates == null) {
return null;
}
return {"note": note, "image": image, "templates": templates};
},
)
.where((data) => data != null)
.listen(
(data) => add(
DataUpdated(
images: data!["image"] as List<ImageNote>,
notes: data["note"] as List<Note>,
templates: data["templates"] as List<NoteTemplate>,
),
),
);
on<LoadNote>(_load);
on<AddNote>(_add);
@ -58,7 +66,13 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
}
Future<void> _dataUpdated(DataUpdated event, Emitter<NoteState> emit) async {
emit(NoteLoaded(notes: event.notes, images: event.images, templates: event.templates));
emit(
NoteLoaded(
notes: event.notes,
images: event.images,
templates: event.templates,
),
);
}
Future<void> _reset(ResetNotes event, Emitter<NoteState> emit) async {
@ -102,11 +116,6 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
emit.call(NoteLoading());
try {
List<String> urls =
event.delivery.images.map((image) => image.url).toList();
debugPrint("IMAGE URLS : $urls");
await repository.loadNotes(event.delivery.id);
await repository.loadTemplates();