saveBookmark method
void
saveBookmark({})
Saves a new bookmark to the list of bookmarks.
The bookmark is created with a unique ID, the provided colorCode
,
surahName
, ayahId
, ayahNumber
, and page
.
The bookmark is added to the list of bookmarks with the same colorCode
,
or a new list is created if there is no existing list.
The bookmarks are saved to the storage after adding the new bookmark.
Calls QuranCtrl.update
after saving the bookmark.
Implementation
void saveBookmark({
required String surahName,
required int ayahId,
required int ayahNumber,
required int page,
required int colorCode,
}) {
final bookmark = BookmarkModel(
id: DateTime.now().millisecondsSinceEpoch,
// إنشاء ID فريد
colorCode: colorCode,
name: surahName,
ayahNumber: ayahNumber,
ayahId: ayahId,
page: page,
);
// إضافة العلامة الجديدة إلى القائمة الموجودة
bookmarks.update(
colorCode,
(existingList) => [...existingList, bookmark],
ifAbsent: () => [bookmark], // إذا لم تكن هناك قائمة، أنشئ واحدة جديدة
);
_quranRepository.saveBookmarks(_flattenBookmarks());
update(['bookmarks']);
QuranCtrl.instance.update();
}