adjustPages method
void
adjustPages(
- int pageIndex,
- PdfViewerController pdfViewerController, {
- bool isAdd = true,
})
Implementation
void adjustPages(
int pageIndex,
PdfViewerController pdfViewerController, {
bool isAdd = true,
}) async {
final newUnderlineHistory = <int, List<AnnotationAction>>{};
final newUnderlineUndoStack = <int, List<AnnotationAction>>{};
// Adjust the history and undo stack to shift annotations accordingly
_underlineHistory.forEach((key, value) {
if (isAdd) {
newUnderlineHistory[key >= pageIndex ? key + 1 : key] = value;
} else {
if (key == pageIndex) {
// Skip the deleted page
} else {
newUnderlineHistory[key > pageIndex ? key - 1 : key] = value;
}
}
});
_underlineUndoStack.forEach((key, value) {
if (isAdd) {
newUnderlineUndoStack[key >= pageIndex ? key + 1 : key] = value;
} else {
if (key == pageIndex) {
// Skip the deleted page
} else {
newUnderlineUndoStack[key > pageIndex ? key - 1 : key] = value;
}
}
});
// Replace the old history and undo stack with the updated versions
_underlineHistory
..clear()
..addAll(newUnderlineHistory);
_underlineUndoStack
..clear()
..addAll(newUnderlineUndoStack);
// Adjust the current page if necessary based on the operation
if (!isAdd && _currentPage > pageIndex) {
_currentPage -= 1;
} else if (isAdd && _currentPage >= pageIndex) {
_currentPage += 1;
}
// Ensure annotations are visible after the adjustment
unhide(pdfViewerController);
notifyListeners();
}