Repository navigation
fix(reader): let the newest reader widget own the visual navigator - #332
Merged
ddfreiling merged 6 commits intoNov 18, 2026
Merged
Conversation
Reopening a book within ~400 ms of going back mounted a second ReadiumReaderWidget before the outgoing one was disposed: the example's outgoing player page rebuilt for the new publication from the shared PublicationBloc. On Android the second widget re-added the singleton navigator's fragment to its own container and crashed with "Can't change container ID of fragment". The outgoing widget's dispose then cleared the Dart current reader and disposed the native navigator that the new widget relied on. - Android: track which widget owns the visual navigator. A superseded widget no longer enables it, a newer widget replaces an older widget's navigator instead of re-attaching its fragment, and visualClose only disposes the caller's own navigator. Applies to EPUB, PDF and comic. - Dart: an older reader's dispose only unregisters itself, matching iOS clearCurrentReaderView(ifIs:). - Example: the outgoing page no longer rebuilds its reader, and the delayed ClosePublication is ignored once another book is opening, instead of closing the newly opened one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A superseded reader widget no longer resets narrationSyncEnabled for the newer reader, since the seed now runs after claimVisualNavigator. The example's ReaderWidget gates rebuilds on ModalRoute.isActive, which is false while the route animates out but true under sheets and pushed routes. Remove the unused epubClose/pdfClose/comicClose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The inactive-route guard misses the initial build, allowing a second native reader to mount during audiobook navigation and compete for singleton ownership.
1 open issue
What changed in this PR
This PR addresses fast book-reopening failures by making the newest reader widget own the shared visual navigator and preventing older widgets from clearing its registration.
Changes:
- Add Android navigator ownership checks and safer fragment disposal.
- Preserve the newer Dart reader registration when an older widget is disposed.
- Scope delayed example-app close events to their publication and limit outgoing-route rebuilds.
| File | Description |
|---|---|
flutter_readium/lib/reader_widget.dart |
Only clears registration when the disposed widget still owns it. |
flutter_readium/example/lib/widgets/reader.widget.dart |
Filters publication updates on inactive routes. |
flutter_readium/example/lib/state/publication_bloc.dart |
Ignores stale close events and centralizes subscription cleanup. |
flutter_readium/example/lib/pages/player.page.dart |
Captures the publication targeted by a delayed close. |
flutter_readium/changelog.d/+reader-overlap-reopen.fixed.md |
Documents the overlapping-reader fix. |
flutter_readium/android/src/main/kotlin/dk/nota/flutterreadium/ReadiumReaderWidget.kt |
Passes widget identity when closing the navigator. |
flutter_readium/android/src/main/kotlin/dk/nota/flutterreadium/ReadiumReader.kt |
Adds ownership-aware navigator claiming and teardown; removes unused close methods. |
flutter_readium/android/src/main/kotlin/dk/nota/flutterreadium/navigators/PdfNavigator.kt |
Skips fragment removal when it is no longer added. |
flutter_readium/android/src/main/kotlin/dk/nota/flutterreadium/navigators/EpubNavigator.kt |
Skips fragment removal when it is no longer added. |
flutter_readium/android/src/main/kotlin/dk/nota/flutterreadium/navigators/ComicNavigator.kt |
Skips fragment removal when it is no longer added. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Nov 17, 2026
The outer PublicationBloc builder could swap an outgoing audiobook page to a new ReaderWidget, whose first build ignores buildWhen and mounts a second native reader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m-abs
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Reopening a book quickly on Android crashed with
IllegalStateException: Can't change container ID of fragment EpubReaderFragment. While the outgoing player page animates out, a newReadiumReaderWidgetmounts for the next book before the old one is disposed. Both callepubEnable, and the singleton navigator's fragment was re-added to the second widget's container.The same overlap broke the reader on both platforms without crashing: the old widget's Dart
_cleanupnulledcurrentReaderWidgetafter the new one registered, sogoForward, preferences and decorations went nowhere.Change
clearCurrentReaderView(ifIs:)).claimVisualNavigatorruns at the start of the main-thread part ofepubEnable/pdfEnable/comicEnable. A superseded widget bails out, and a navigator owned by an older widget is disposed first.visualClose(widget)only tears down the navigator if that widget owns it. Navigatordispose()skips a fragment that is no longer added.ReadiumReaderWidget._cleanuponly clearscurrentReaderWidgetif it is still this widget.ClosePublicationcarries the publication it closes and is ignored once another one is opening or open, so the delayed close after pop no longer closes the next book.ReaderWidgetstops rebuilding once its route is no longer active, so an outgoing page does not mount a second reader.epubClose/pdfClose/comicClose.Review notes
ReaderStatus.Closedwhile the new reader is open, as on iOS. Left for a follow-up so both platforms change together.Verification
mainon a Galaxy S23 by going back and opening another book within ~100 ms (adb input).goForwardmoves it. A slow reopen (3 s) also works.ktlint --format,./gradlew :flutter_readium:compileDebugKotlin,bin/format,bin/analyze,bin/changelog check.Not covered
_cleanupchange applies there too.🤖 Generated with Claude Code