refactor: replace numeric tab indexes with NavigationTabId

This commit is contained in:
edde746
2026-03-15 22:31:54 +01:00
parent af0de5c0a9
commit db6161d84e
6 changed files with 208 additions and 324 deletions
+40
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import '../services/gamepad_service.dart';
import '../screens/main_screen.dart';
import '../widgets/focusable_tab_chip.dart';
/// Mixin that provides common tab navigation infrastructure.
///
@@ -83,4 +84,43 @@ mixin TabNavigationMixin<T extends StatefulWidget> on State<T>, TickerProviderSt
void onTabBarBack() {
MainScreenFocusScope.of(context)?.focusSidebar();
}
/// Shared tab chip builder — eliminates duplication between screens.
Widget buildTabChip(
String label,
int index, {
required VoidCallback onSelectWhenActive,
required VoidCallback onNavigateDown,
VoidCallback? onNavigateRightFromLast,
}) {
final isSelected = tabController.index == index;
return FocusableTabChip(
label: label,
isSelected: isSelected,
focusNode: getTabChipFocusNode(index),
onSelect: () {
if (isSelected) {
onSelectWhenActive();
} else {
setState(() { tabController.index = index; });
}
},
onNavigateLeft: index > 0
? () {
final newIndex = index - 1;
setState(() { suppressAutoFocus = true; tabController.index = newIndex; });
getTabChipFocusNode(newIndex).requestFocus();
}
: onTabBarBack,
onNavigateRight: index < tabCount - 1
? () {
final newIndex = index + 1;
setState(() { suppressAutoFocus = true; tabController.index = newIndex; });
getTabChipFocusNode(newIndex).requestFocus();
}
: onNavigateRightFromLast,
onNavigateDown: onNavigateDown,
onBack: onTabBarBack,
);
}
}