Fixed missing loading spinner due to seeded streams in note repository.
This commit is contained in:
@ -29,13 +29,21 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
repository.notes,
|
||||
repository.images,
|
||||
repository.templates,
|
||||
(note, image, templates) => {"note": note, "image": image, "templates": templates},
|
||||
).listen(
|
||||
(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>,
|
||||
images: data!["image"] as List<ImageNote>,
|
||||
notes: data["note"] as List<Note>,
|
||||
templates: data["templates"] as List<NoteTemplate>
|
||||
templates: data["templates"] as List<NoteTemplate>,
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -121,14 +121,9 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
void _openSignatureView(Delivery delivery) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return BlocProvider(
|
||||
create:
|
||||
(context) => NoteBloc(
|
||||
repository: NoteRepository(service: NoteService()),
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
deliveryId: delivery.id,
|
||||
),
|
||||
builder: (_) {
|
||||
return BlocProvider.value(
|
||||
value: context.read<NoteBloc>(),
|
||||
child: SignatureView(onSigned: _onSign, delivery: delivery),
|
||||
);
|
||||
},
|
||||
@ -160,11 +155,13 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 20),
|
||||
child: FilledButton(
|
||||
onPressed:
|
||||
() =>
|
||||
_step == _steps.length - 1
|
||||
? _openSignatureView(delivery)
|
||||
: _clickForward,
|
||||
onPressed: () {
|
||||
if (_step == _steps.length - 1) {
|
||||
_openSignatureView(delivery);
|
||||
} else {
|
||||
_clickForward();
|
||||
}
|
||||
},
|
||||
child:
|
||||
_step == _steps.length - 1
|
||||
? const Text("Unterschreiben")
|
||||
|
||||
@ -7,22 +7,24 @@ import 'package:rxdart/rxdart.dart';
|
||||
class NoteRepository {
|
||||
final NoteService service;
|
||||
|
||||
final _notesStream = BehaviorSubject<List<Note>>.seeded([]);
|
||||
final _imageNoteStream = BehaviorSubject<List<ImageNote>>.seeded([]);
|
||||
final _noteTemplateStream = BehaviorSubject<List<NoteTemplate>>.seeded([]);
|
||||
final _notesStream = BehaviorSubject<List<Note>?>.seeded(null);
|
||||
final _imageNoteStream = BehaviorSubject<List<ImageNote>?>.seeded(null);
|
||||
final _noteTemplateStream = BehaviorSubject<List<NoteTemplate>?>.seeded(null);
|
||||
|
||||
Stream<List<Note>> get notes => _notesStream.stream;
|
||||
Stream<List<ImageNote>> get images => _imageNoteStream.stream;
|
||||
Stream<List<NoteTemplate>> get templates => _noteTemplateStream.stream;
|
||||
Stream<List<Note>?> get notes => _notesStream.stream;
|
||||
Stream<List<ImageNote>?> get images => _imageNoteStream.stream;
|
||||
Stream<List<NoteTemplate>?> get templates => _noteTemplateStream.stream;
|
||||
|
||||
List<Note> get _currentNotes => _notesStream.value ?? [];
|
||||
List<ImageNote> get _currentImages => _imageNoteStream.value ?? [];
|
||||
|
||||
NoteRepository({required this.service});
|
||||
|
||||
Future<void> addNote(String deliveryId, String content) async {
|
||||
final note = await service.addNote(content, int.parse(deliveryId));
|
||||
final currentNotes = _notesStream.value;
|
||||
currentNotes.add(note);
|
||||
_currentNotes.add(note);
|
||||
|
||||
_notesStream.add(currentNotes);
|
||||
_notesStream.add(_currentNotes);
|
||||
}
|
||||
|
||||
Future<void> editNote(String noteId, String content) async {
|
||||
@ -30,17 +32,19 @@ class NoteRepository {
|
||||
await service.editNote(newNote);
|
||||
|
||||
final currentNotes = _notesStream.value;
|
||||
final index = currentNotes.indexWhere((note) => note.id == int.parse(noteId));
|
||||
currentNotes[index] = newNote;
|
||||
final index = _currentNotes.indexWhere((note) => note.id == int.parse(noteId));
|
||||
|
||||
if (index != -1) {
|
||||
_currentNotes[index] = newNote;
|
||||
_notesStream.add(currentNotes);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteNote(String noteId) async {
|
||||
await service.deleteNote(int.parse(noteId));
|
||||
final currentNotes = _notesStream.value;
|
||||
final index = currentNotes.indexWhere((note) => note.id == int.parse(noteId));
|
||||
currentNotes.removeAt(index);
|
||||
final index = _currentNotes.indexWhere((note) => note.id == int.parse(noteId));
|
||||
_currentNotes.removeAt(index);
|
||||
|
||||
_notesStream.add(currentNotes);
|
||||
}
|
||||
@ -66,9 +70,8 @@ class NoteRepository {
|
||||
bytes,
|
||||
"image/png",
|
||||
);
|
||||
final imageNotes = _imageNoteStream.value;
|
||||
imageNotes.add(ImageNote.make(objectId, fileName, bytes));
|
||||
_imageNoteStream.add(imageNotes);
|
||||
_currentImages.add(ImageNote.make(objectId, fileName, bytes));
|
||||
_imageNoteStream.add(_currentImages);
|
||||
}
|
||||
|
||||
Future<void> addNamedImage(String deliveryId, Uint8List bytes, String filename) async {
|
||||
@ -79,18 +82,15 @@ class NoteRepository {
|
||||
"image/png",
|
||||
);
|
||||
|
||||
final imageNotes = _imageNoteStream.value;
|
||||
imageNotes.add(ImageNote.make(objectId, filename, bytes));
|
||||
_imageNoteStream.add(imageNotes);
|
||||
_currentImages.add(ImageNote.make(objectId, filename, bytes));
|
||||
_imageNoteStream.add(_currentImages);
|
||||
}
|
||||
|
||||
Future<void> deleteImage(String deliveryId, String objectId) async {
|
||||
await service.removeImage(objectId);
|
||||
|
||||
final images = _imageNoteStream.value;
|
||||
final index = images.indexWhere((imageNote) => imageNote.objectId == objectId);
|
||||
images.removeAt(index);
|
||||
|
||||
_imageNoteStream.add(images);
|
||||
final index = _currentImages.indexWhere((imageNote) => imageNote.objectId == objectId);
|
||||
_currentImages.removeAt(index);
|
||||
_imageNoteStream.add(_currentImages);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,6 @@ class NoteService {
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
NoteGetResponseDTO responseDto = NoteGetResponseDTO.fromJson(
|
||||
responseJson,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user