Fix Async Transaction Bug and Category Management Issues #489
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
This PR consolidates four related fixes to improve stability and correctness in transaction handling and category management across the app:
1. Async Write Transaction Bug
2. Category Selection in Manga Detail View
3. Category Removal Reference Cleanup
4. Tab‐Controller Edge Case & Code Cleanup
🔍 Details
1. Fix async write transaction bug
- Issue: Switching the write transaction to fully async led to a nested‑transaction error:
IsarError: Cannot perform this operation from within an active transaction. Isar does not support nesting transactions.
- Resolution: Ensure that the write transaction is fully awaited and not re‑entered before completion.
2. Fix "Set categories" in
manga_detail_view
- Issue: The category selection dialog did not reflect the current categories for a library item.
- Resolution: Updated the dialog data source so it correctly marks which categories the item already belongs to.
3. Fix category removal bug
- Issue: Removing a category did not update the linked manga items, causing them to disappear from the library view.
- Resolution: On category deletion, remove the reference from each affected item. Items without any category now fall back into the “Default” category.
4. Fix tab‐controller edge case & remove redundant code
- Issue A: If the user hid the only remaining category,
tabCount
became <= 0, triggering an assertion inTabController
:_AssertionError ('package:flutter/src/material/tab_controller.dart': Failed assertion: line 116 pos 15: 'initialIndex >= 0 && (length == 0 || initialIndex < length)': is not true.)
- Issue B: Duplicate variables and multiple
ref.watch
calls created unnecessary code churn.- Resolutions:
- Added a guard so that when
tabCount <= 0
, the UI shows_bodyWithoutCategories
instead of instantiating aTabController
.- Consolidated redundant variables and grouped all
ref.watch
calls into a single, DRY implementation.✅ Testing & Validation