getSurahsByPageNumber method

List<SurahModel> getSurahsByPageNumber(
  1. int pageNumber
)

Retrieves a list of Surahs present on a specific page.

Parameters: pageNumber (int): The index of the page for which to retrieve the Surahs.

Returns: List<SurahModel>: A list of SurahModel representing the Surahs on the specified page.

Implementation

List<SurahModel> getSurahsByPageNumber(int pageNumber) {
  if (getPageAyahsByIndex(pageNumber - 1).isEmpty) return [];
  List<AyahModel> pageAyahs = getPageAyahsByIndex(pageNumber - 1);
  List<SurahModel> surahsOnPage = [];
  for (AyahModel ayah in pageAyahs) {
    SurahModel surah = state.surahs.firstWhere((s) => s.ayahs.contains(ayah),
        orElse: () => SurahModel(
              surahNumber: 1,
              arabicName: 'Unknown',
              englishName: 'Unknown',
              revelationType: 'Unknown',
              ayahs: [],
              isDownloadedFonts: false,
            ));
    if (!surahsOnPage.any((s) => s.surahNumber == surah.surahNumber) &&
        surah.surahNumber != -1) {
      surahsOnPage.add(surah);
    }
  }
  return surahsOnPage;
}