adjustPages method
Adjusts the highlight and undo stacks when pages are added or removed.
pageIndex
- The index where the page was added or removed.
isAdd
- Whether a page was added (true) or removed (false).
Implementation
Future<void> adjustPages(
int pageIndex,
PdfViewerController pdfViewerController, {
bool isAdd = true,
}) async {
final newHighlightHistory = <int, List<AnnotationAction>>{};
final newHighlightUndoStack = <int, List<AnnotationAction>>{};
_highlightHistory.forEach((key, value) {
if (isAdd) {
newHighlightHistory[key >= pageIndex ? key + 1 : key] = value;
} else {
if (key != pageIndex) {
newHighlightHistory[key > pageIndex ? key - 1 : key] = value;
}
}
});
_highlightUndoStack.forEach((key, value) {
if (isAdd) {
newHighlightUndoStack[key >= pageIndex ? key + 1 : key] = value;
} else {
if (key != pageIndex) {
newHighlightUndoStack[key > pageIndex ? key - 1 : key] = value;
}
}
});
_highlightHistory
..clear()
..addAll(newHighlightHistory);
_highlightUndoStack
..clear()
..addAll(newHighlightUndoStack);
if (!isAdd && _currentPage > pageIndex) {
_currentPage -= 1;
} else if (isAdd && _currentPage >= pageIndex) {
_currentPage += 1;
}
// Restore annotations after page structure changes
unhide(pdfViewerController);
notifyListeners();
}