updateContentAccordingChapter method

dynamic updateContentAccordingChapter(
  1. int chapterIndex
)

Implementation

updateContentAccordingChapter(int chapterIndex) async {
  ///Set current chapter index
  await bookProgress.setCurrentChapterIndex(bookId, chapterIndex);

  String content = '';

  await Future.wait(epubBook.Chapters!.map((EpubChapter chapter) async {
    content = epubBook.Chapters![chapterIndex].HtmlContent!;

    List<EpubChapter>? subChapters = chapter.SubChapters;
    if (subChapters != null && subChapters.isNotEmpty) {
      for (int i = 0; i < subChapters.length; i++) {
        content = content + subChapters[i].HtmlContent!;
      }
    } else {
      subChapters?.forEach((element) {
        if (element.Title == epubBook.Chapters![chapterIndex].Title) {
          content = element.HtmlContent!;
        }
      });
    }
  }));

  htmlContent = content;
  textContent = parse(htmlContent).documentElement!.text;

  if (isHTML(textContent)) {
    innerHtmlContent = textContent;
  }
  controllerPaging.paginate();

  setupNavButtons();
}