setCurrentChapterIndex method
Implementation
Future<bool> setCurrentChapterIndex(String bookId, int chapterIndex) async {
try {
BookProgressModel? oldBookProgressModel = await isar.bookProgressModels
.where()
.filter()
.bookIdEqualTo(bookId)
.findFirst();
if (oldBookProgressModel != null) {
oldBookProgressModel.currentChapterIndex = chapterIndex;
await isar.writeTxn(() async {
isar.bookProgressModels.put(oldBookProgressModel);
});
} else {
var newBookProgressModel = BookProgressModel(
currentPageIndex: 0,
currentChapterIndex: chapterIndex,
bookId: bookId);
await isar.writeTxn(() async {
isar.bookProgressModels.put(newBookProgressModel);
});
}
return true;
} catch (e) {
return false;
}
}