I'm using syncfusion_flutter_pdfviewer: ^30.2.7
I'm adding annotation with builtin toolbox
now I want to save the information of the annotation somewhere, so I could add them automatically when pdf opened next time
but Annotation class does not return any information about added annotation, and adding annotation using controller is really messy
SfPdfViewer.asset(
"lib/assets/sample.pdf",
controller: c.controller,
undoController: c.undoController,
scrollDirection: PdfScrollDirection.vertical,
interactionMode: c.panMode.value ? PdfInteractionMode.pan : PdfInteractionMode.selection,
pageSpacing: 20,
onPageChanged: (PdfPageChangedDetails details) => c.pageNumber(details.newPageNumber),
onTextSelectionChanged: (PdfTextSelectionChangedDetails details) {
c.selectedText.value = details.selectedText ?? "";
},
onAnnotationAdded: (Annotation annotation) {
annotation.color = c.selectedColor.value;
UAnnotationType type = UAnnotationType.highlight;
if (annotation is UnderlineAnnotation) {
type = UAnnotationType.underline;
}
if (annotation is HighlightAnnotation) {
type = UAnnotationType.highlight;
}
if (annotation is SquigglyAnnotation) {
type = UAnnotationType.squiggly;
}
if (annotation is StrikethroughAnnotation) {
type = UAnnotationType.strikeout;
}
if (annotation is StickyNoteAnnotation) {
type = UAnnotationType.stickyNote;
}
c.addAnnotation(
UAnnotation(
type: type,
pageNumber: annotation.pageNumber,
color: c.selectedColor.value,
text: c.selectedText.value,
),
);
},
onAnnotationDeselected: (Annotation annotation) {},
onAnnotationEdited: (Annotation annotation) {},
onAnnotationRemoved: (Annotation annotation) {},
onAnnotationSelected: (Annotation annotation) {},
onTap: (PdfGestureDetails details) {
if (c.addNoteMode.value) {
c.addStickyNote(details.pagePosition);
}
},
)
class UAnnotation {
final String id = UUUID.uuidV7();
final UAnnotationType type;
final Color color;
final int pageNumber;
final String text;
UAnnotation({
required this.type,
required this.pageNumber,
required this.color,
required this.text,
});
}