prepareFonts method

Future<void> prepareFonts(
  1. int pageIndex, {
  2. bool isFontsLocal = false,
})

Prepares fonts for the specified page index and adjacent pages.

This method asynchronously loads the font for the given pageIndex and additionally preloads fonts for the next four pages if the pageIndex is less than 600, and the previous four pages if the pageIndex is greater than or equal to 4. This ensures smoother font loading experience as the user navigates through pages.

pageIndex - The index of the page for which the font and its adjacent pages' fonts should be prepared.

Returns a Future that completes when all specified fonts have been successfully loaded.

Implementation

Future<void> prepareFonts(int pageIndex, {bool isFontsLocal = false}) async {
  await loadFont(pageIndex, isFontsLocal: isFontsLocal);
  if (pageIndex < 600) {
    for (int i = pageIndex + 1; i < pageIndex + 5; i++) {
      await loadFont(i, isFontsLocal: isFontsLocal);
    }
  }
  if (pageIndex >= 4) {
    for (int i = pageIndex - 1; i > pageIndex - 5; i--) {
      await loadFont(i, isFontsLocal: isFontsLocal);
    }
  }
}