forked from 4akloon/epub_plus
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
The current code looks like this, which does not handle the case where a chapter has subchapters.
// Find chapter with matching content file
final chapters = _bookRef.getChapters();
return chapters.firstWhere(
(chapter) => chapter.contentFileName == manifestItem!.href,
orElse: () => throw StateError('Chapter not found'),
);My proposed solution is to add a flatten function.
List<EpubChapterRef> flattenChapter(EpubChapterRef chapter) {
return [chapter, ...chapter.subChapters.expand(flattenChapter)];
}
/// Gets a chapter reference by spine index.
EpubChapterRef? _getChapterBySpineIndex(int spineIndex) {
// ....
// Find chapter with matching content file
final chapters = bookRef.getChapters().expand(flattenChapter);
return chapters.firstWhere(
(chapter) => chapter.contentFileName == manifestItem!.href,
orElse: () => throw StateError('Chapter not found'),
);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels