Skip to content

Conversation

NBA2K1
Copy link
Contributor

@NBA2K1 NBA2K1 commented Jun 15, 2025

📝 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 in TabController:
_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 a TabController.
- Consolidated redundant variables and grouped all ref.watch calls into a single, DRY implementation.
 

✅ Testing & Validation

  • Verified that the async transaction no longer triggers nesting errors under heavy load.
  • Manually tested category selection and saw correct pre‐selected state in the dialog.
  • Confirmed that deleting a category reassigns orphaned items to “Default” and they reappear in the library.
  • Hid the last category and ensured the fallback view renders without exceptions.

NBA2K1 added 4 commits June 15, 2025 14:07
When removing a category, the items inside the category were not being updated, removing the link to the removed category.
That lead to the items disappearance from the library.

Now the reference from the item to the deleted category is deleted. Those items show up in the "Default" category.
Before fixing the Category Removal Bug (commit 5853728), the "Default" Category would be empty when removing a populated category.

So when there is only one Category left, and the user hides that one Category, `tabCount` would be <= 0, leading to an Exception:

```
_AssertionError ('package:flutter/src/material/tab_controller.dart': Failed assertion: line 116 pos 15: 'initialIndex >= 0 && (length == 0 || initialIndex < length)': is not true.)
```

Now there is a check (`tabCount <= 0`), that IF tabCount is ever <= 0, it would show `_bodyWithoutCategories`.
@kodjodevf kodjodevf merged commit 7e1b06f into kodjodevf:main Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants