Enhanced signature step and adjusted note bloc
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
import '../../../../model/delivery.dart';
|
||||
import 'note_event.dart';
|
||||
import 'note_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/repository/note_repository.dart';
|
||||
@ -15,20 +18,25 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
final OperationBloc opBloc;
|
||||
final String deliveryId;
|
||||
|
||||
StreamSubscription? _noteSubscription;
|
||||
StreamSubscription? _imageSubscription;
|
||||
StreamSubscription? _combinedSubscription;
|
||||
|
||||
NoteBloc({required this.repository, required this.opBloc, required this.deliveryId})
|
||||
: super(NoteInitial()) {
|
||||
repository.loadNotes(deliveryId);
|
||||
|
||||
_noteSubscription = repository.notes.listen((notes) {
|
||||
add(NotesUpdated(notes: notes));
|
||||
});
|
||||
|
||||
_imageSubscription = repository.images.listen((images) {
|
||||
add(ImageUpdated(images: images));
|
||||
});
|
||||
NoteBloc({
|
||||
required this.repository,
|
||||
required this.opBloc,
|
||||
required this.deliveryId,
|
||||
}) : super(NoteInitial()) {
|
||||
_combinedSubscription = CombineLatestStream.combine2(
|
||||
repository.notes,
|
||||
repository.images,
|
||||
(note, image) => {"note": note, "image": image},
|
||||
).listen(
|
||||
(data) => add(
|
||||
DataUpdated(
|
||||
images: data["image"] as List<ImageNote>,
|
||||
notes: data["note"] as List<Note>,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
on<LoadNote>(_load);
|
||||
on<AddNote>(_add);
|
||||
@ -37,36 +45,28 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
on<AddImageNote>(_upload);
|
||||
on<RemoveImageNote>(_removeImage);
|
||||
on<ResetNotes>(_reset);
|
||||
on<NotesUpdated>(_noteUpdated);
|
||||
on<ImageUpdated>(_imageUpdated);
|
||||
on<DataUpdated>(_dataUpdated);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_noteSubscription?.cancel();
|
||||
_imageSubscription?.cancel();
|
||||
_combinedSubscription?.cancel();
|
||||
|
||||
return super.close();
|
||||
}
|
||||
|
||||
Future<void> _imageUpdated(ImageUpdated event, Emitter<NoteState> emit) async {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
emit.call(currentState.copyWith(images: event.images));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _noteUpdated(NotesUpdated event, Emitter<NoteState> emit) async {
|
||||
emit(NoteLoaded(notes: event.notes));
|
||||
Future<void> _dataUpdated(DataUpdated event, Emitter<NoteState> emit) async {
|
||||
emit(NoteLoaded(notes: event.notes, images: event.images));
|
||||
}
|
||||
|
||||
Future<void> _reset(ResetNotes event, Emitter<NoteState> emit) async {
|
||||
emit.call(NoteInitial());
|
||||
}
|
||||
|
||||
Future<void> _removeImage(RemoveImageNote event,
|
||||
Emitter<NoteState> emit,) async {
|
||||
Future<void> _removeImage(
|
||||
RemoveImageNote event,
|
||||
Emitter<NoteState> emit,
|
||||
) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
@ -101,7 +101,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
|
||||
try {
|
||||
List<String> urls =
|
||||
event.delivery.images.map((image) => image.url).toList();
|
||||
event.delivery.images.map((image) => image.url).toList();
|
||||
|
||||
debugPrint("IMAGE URLS : $urls");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user