MangasListState previously stored selected manga IDs as List<int>.
Every visible library card called .contains() on that list once per
rebuild to determine its highlight state, making each check O(n) in
the number of selected items. The provider's own update/selectAll/
selectSome methods also used .contains() and .remove() on a List.
Change the state type to Set<int> throughout, making all membership
checks O(1). Updated all consumers: library_gridview_widget,
library_listview_widget, library_app_bar, library_dialogs, and
MangasSetIsReadState.
call `_processCropBorders()` once, from _initCurrentIndex and after new pages arrive.
Also make _processCropBorders idempotent by the existing _cropBorderCheckList guard
fix for the "jump back" bug that occurred when scrolling up in vertical continuous and webtoon reader modes.
- `ChapterPreloadManager` was maintaining its own `_currentIndex`.
- When prepending previous chapter pages, the index was being incremented
twice (once in the manager + once in `_handlePrevChapterPrepended`).
- This caused `itemScrollController.jumpTo()` to overshoot, resulting in
a visible jump forward (perceived as "jump back" while trying to scroll up).
- Removed all index management (`_currentIndex`, getter, setter, startIndex)
from `ChapterPreloadManager` and `ReaderMemoryManagement`.
- `ChapterPreloadManager` is now a pure data container (only manages `_pages`).
- `_handlePrevChapterPrepended` now captures the **current visible top index**
*before* prepending and adjusts the scroll position only once.
- `_readProgressListener` is now the single source of truth for `_currentIndex`.
- Removed stale `initialScrollIndex` logic from preload initialization.
Introduce a unique `ValueKey` for each page (chapter ID + page index) and wrap items in `KeyedSubtree`. This ensures Flutter can correctly preserve widget identity when the preload manager inserts or prepends pages.
Previously, every `setState` triggered by page preloading caused the entire list to rebuild, leading to visible lag. With stable keys, only newly added pages rebuild while existing ones retain their state.
This significantly reduces jank, improves scroll smoothness, and makes chapter transitions nearly seamless.
`ChapterPreloadManager.preloadPrevChapter` does `_currentIndex += prependCount` (internal manager index).
Then `_handlePrevChapterPrepended` in `reader_view.dart` does the exact same thing again to the UI’s `_currentIndex` before calling `jumpTo`.
The UI state already handles the adjustment + `jumpTo` correctly.
The manager’s internal `_currentIndex` is not needed for continuous mode (the `ItemPositionsListener` overrides it anyway).
════════ Exception caught by Flutter framework ═════════════════════════════════
The following assertion was thrown during runApp:
Zone mismatch.
The Flutter bindings were initialized in a different zone than is now being used. This will likely cause confusion and bugs as any zone-specific configuration will inconsistently use the configuration of the original binding initialization zone or this zone based on hard-to-predict factors such as which zone was active when a particular callback was set.
It is important to use the same zone when calling `ensureInitialized` on the binding as when calling `runApp` later.
To make this warning fatal, set BindingBase.debugZoneErrorsAreFatal to true before the bindings are initialized (i.e. as the first statement in `void main() { }`).
When the exception was thrown, this was the stack:
#0 BindingBase.debugCheckZone.<anonymous closure> (package:flutter/src/foundation/binding.dart:519:31)
binding.dart:519
#1 BindingBase.debugCheckZone (package:flutter/src/foundation/binding.dart:525:6)
binding.dart:525
#2 _runWidget (package:flutter/src/widgets/binding.dart:1680:18)
binding.dart:1680
#3 runApp (package:flutter/src/widgets/binding.dart:1616:3)
binding.dart:1616
#4 main.<anonymous closure> (package:mangayomi/main.dart:108:7)
main.dart:108
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════