Added custom tour ordering
This commit is contained in:
@ -15,7 +15,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
final OperationBloc opBloc;
|
||||
|
||||
NoteBloc({required this.repository, required this.opBloc})
|
||||
: super(NoteInitial()) {
|
||||
: super(NoteInitial()) {
|
||||
on<LoadNote>(_load);
|
||||
on<AddNote>(_add);
|
||||
on<EditNote>(_edit);
|
||||
@ -23,16 +23,44 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
on<AddImageNote>(_upload);
|
||||
on<RemoveImageNote>(_removeImage);
|
||||
on<ResetNotes>(_reset);
|
||||
on<AddNoteOffline>(_addOffline);
|
||||
}
|
||||
|
||||
Future<void> _reset(ResetNotes event, Emitter<NoteState> emit) async {
|
||||
emit.call(NoteInitial());
|
||||
}
|
||||
|
||||
Future<void> _removeImage(
|
||||
RemoveImageNote event,
|
||||
Emitter<NoteState> emit,
|
||||
) async {
|
||||
Future<void> _addOffline(AddNoteOffline event,
|
||||
Emitter<NoteState> emit,) async {
|
||||
if (state is NoteInitial) {
|
||||
emit(
|
||||
NoteLoadedBase(
|
||||
notes: [Note(content: event.note, id: int.parse(event.noteId))],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is NoteLoadedBase) {
|
||||
emit(
|
||||
NoteLoadedBase(
|
||||
notes: [
|
||||
...(state as NoteLoadedBase).notes,
|
||||
Note(content: event.note, id: int.parse(event.noteId)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is NoteLoaded) {
|
||||
final current = state as NoteLoaded;
|
||||
emit(NoteLoaded(notes: [...current.notes, Note(content: event.note, id: int.parse(event.noteId))],
|
||||
templates: [...current.templates],
|
||||
images: [...current.images]));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _removeImage(RemoveImageNote event,
|
||||
Emitter<NoteState> emit,) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
@ -43,9 +71,9 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
emit.call(
|
||||
currentState.copyWith(
|
||||
images:
|
||||
currentState.images
|
||||
.where((image) => image.$1.objectId != event.objectId)
|
||||
.toList(),
|
||||
currentState.images
|
||||
.where((image) => image.$1.objectId != event.objectId)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -89,7 +117,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();
|
||||
List<Note> notes = await repository.loadNotes(event.delivery.id);
|
||||
List<NoteTemplate> templates = await repository.loadTemplates();
|
||||
List<Uint8List> images = await repository.loadImages(urls);
|
||||
@ -100,7 +128,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
templates: templates,
|
||||
images: List.generate(
|
||||
images.length,
|
||||
(index) => (event.delivery.images[index], images[index]),
|
||||
(index) => (event.delivery.images[index], images[index]),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -148,7 +176,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
if (currentState is NoteLoaded) {
|
||||
List<Note> refreshedNotes = [
|
||||
...currentState.notes.where(
|
||||
(note) => note.id != int.parse(event.noteId),
|
||||
(note) => note.id != int.parse(event.noteId),
|
||||
),
|
||||
Note(content: event.content, id: int.parse(event.noteId)),
|
||||
];
|
||||
@ -173,9 +201,9 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
List<Note> refreshedNotes =
|
||||
currentState.notes
|
||||
.where((note) => note.id != int.parse(event.noteId))
|
||||
.toList();
|
||||
currentState.notes
|
||||
.where((note) => note.id != int.parse(event.noteId))
|
||||
.toList();
|
||||
|
||||
emit.call(currentState.copyWith(notes: refreshedNotes));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user