getHizbQuarterDisplayByPage method
Retrieves the display string for the Hizb quarter of the given page number.
This method returns a string indicating the Hizb quarter of the given page number. It takes into account whether the Hizb quarter is new or the same as the previous page's Hizb quarter, and formats the string accordingly.
Parameters: pageNumber (int): The page number for which to retrieve the Hizb quarter display string.
Returns:
String: A string indicating the Hizb quarter of the given page number.
Implementation
String getHizbQuarterDisplayByPage(int pageNumber) {
final List<AyahModel> currentPageAyahs =
state.allAyahs.where((ayah) => ayah.page == pageNumber).toList();
if (currentPageAyahs.isEmpty) return "";
// Find the highest Hizb quarter on the current page
int? currentMaxHizbQuarter =
currentPageAyahs.map((ayah) => ayah.hizb!).reduce(math.max);
// Store/update the highest Hizb quarter for this page
state.pageToHizbQuarterMap[pageNumber] = currentMaxHizbQuarter;
// For displaying the Hizb quarter, check if this is a new Hizb quarter different from the previous page's Hizb quarter
// For the first page, there is no "previous page" to compare, so display its Hizb quarter
if (pageNumber == 1 ||
state.pageToHizbQuarterMap[pageNumber - 1] != currentMaxHizbQuarter) {
int hizbNumber = ((currentMaxHizbQuarter - 1) ~/ 4) + 1;
int quarterPosition = (currentMaxHizbQuarter - 1) % 4;
switch (quarterPosition) {
case 0:
return "الحزب ${'$hizbNumber'.convertNumbersAccordingToLang()}";
case 1:
return "١/٤ الحزب ${'$hizbNumber'.convertNumbersAccordingToLang()}";
case 2:
return "١/٢ الحزب ${'$hizbNumber'.convertNumbersAccordingToLang()}";
case 3:
return "٣/٤ الحزب ${'$hizbNumber'.convertNumbersAccordingToLang()}";
default:
return "";
}
}
// If the page's Hizb quarter is the same as the previous page, do not display it again
return "";
}