addOrUpdate static method
Implementation
static void addOrUpdate(HighlightModel highlight) {
final all = _readAll();
// Check for existing highlight at same position → update color
final idx = all.indexWhere((h) =>
h.bookId == highlight.bookId &&
h.chapterIndex == highlight.chapterIndex &&
h.paragraphKey == highlight.paragraphKey &&
h.startIndex == highlight.startIndex &&
h.endIndex == highlight.endIndex);
if (idx != -1) {
all[idx] = highlight;
} else {
all.add(highlight);
}
_writeAll(all);
}