Fix "Show extensions" Button

The "Show extensions" Button was not working properly when categories were hidden.
An Exception would throw:
```
_AssertionError ('package:flutter/src/material/tab_controller.dart': Failed assertion: line 202 pos 12: 'value >= 0 && (value < length || length == 0)': is not true.)
```
And jump to the end of the tab list regardless of where you clicked the button.
This commit is contained in:
NBA2K1 2025-12-29 05:02:43 +01:00
parent 42f1dcff92
commit 7664e38cfd
2 changed files with 15 additions and 7 deletions

View file

@ -197,6 +197,7 @@ class _BrowseScreenState extends ConsumerState<BrowseScreen>
if (tab.kind == BrowseTabKind.sources) {
return SourcesScreen(
itemType: tab.type,
tabs: _tabList,
tabIndex: (index) => _tabBarController.animateTo(index),
);
} else {

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mangayomi/modules/browse/browse_screen.dart';
import 'package:mangayomi/modules/widgets/custom_sliver_grouped_list_view.dart';
import 'package:isar_community/isar.dart';
import 'package:mangayomi/main.dart';
@ -11,10 +12,12 @@ import 'package:mangayomi/utils/language.dart';
class SourcesScreen extends ConsumerStatefulWidget {
final Function(int) tabIndex;
final List<BrowseTab> tabs;
final ItemType itemType;
const SourcesScreen({
required this.tabIndex,
required this.itemType,
required this.tabs,
super.key,
});
@ -62,13 +65,17 @@ class _SourcesScreenState extends ConsumerState<SourcesScreen> {
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton.icon(
onPressed: () => widget.tabIndex(
widget.itemType == ItemType.manga
? 3
: widget.itemType == ItemType.anime
? 4
: 5,
),
onPressed: () {
final extensionIndex = widget.tabs.indexWhere(
(t) =>
t.type == widget.itemType &&
t.kind == BrowseTabKind.extensions,
);
if (extensionIndex != -1) {
widget.tabIndex(extensionIndex);
}
},
icon: const Icon(Icons.extension_rounded),
label: Text(context.l10n.show_extensions),
),