generated from dellevin/template
epub阅读添加搜索
This commit is contained in:
@@ -18,18 +18,31 @@ mixin _ProgressMixin on State<ReaderScreen> {
|
||||
Timer? get progressDebouncer;
|
||||
set progressDebouncer(Timer? v);
|
||||
|
||||
Map<int, int> get chapterPageCounts;
|
||||
|
||||
void updateProgressDebounced() {
|
||||
progressDebouncer?.cancel();
|
||||
progressDebouncer = Timer(const Duration(milliseconds: 150), () {
|
||||
if (!mounted) return;
|
||||
if (isWebViewLoading) return;
|
||||
|
||||
final pageInChapterStr =
|
||||
'${currentPageInChapter + 1}/$totalPagesInChapter';
|
||||
final totalChapters = bookSession.spine.length;
|
||||
|
||||
if (displayProgress != pageInChapterStr) {
|
||||
// 用当前章节页数估算全书页数
|
||||
final avgPages = totalPagesInChapter > 0 ? totalPagesInChapter : 1;
|
||||
final estimatedTotalPages = avgPages * totalChapters;
|
||||
|
||||
// 估算绝对页码 = 已读章节数 * 平均每章页数 + 当前页
|
||||
final estimatedAbsolutePage =
|
||||
currentSpineItemIndex * avgPages + currentPageInChapter + 1;
|
||||
|
||||
final pageStr = totalChapters > 0
|
||||
? '$estimatedAbsolutePage/$estimatedTotalPages'
|
||||
: '${currentPageInChapter + 1}/$totalPagesInChapter';
|
||||
|
||||
if (displayProgress != pageStr) {
|
||||
setState(() {
|
||||
displayProgress = pageInChapterStr;
|
||||
displayProgress = pageStr;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user