fix: scope navigation callbacks to active owners

This commit is contained in:
edde746
2026-07-12 18:59:27 +02:00
parent cd88f73f05
commit 0ef1e773bb
7 changed files with 134 additions and 64 deletions
+9 -6
View File
@@ -29,22 +29,25 @@ mixin TabNavigationMixin<T extends StatefulWidget> on State<T>, TickerProviderSt
/// Number of tabs — derived from [tabChipFocusNodes].
int get tabCount => tabChipFocusNodes.length;
/// Initialise the [TabController] and register gamepad callbacks.
/// Initialise the [TabController] and register owner-scoped gamepad callbacks.
/// Call from [initState].
void initTabNavigation() {
tabController = TabController(length: tabCount, vsync: this);
tabController.addListener(onTabChanged);
GamepadService.onL1Pressed = goToPreviousTab;
GamepadService.onR1Pressed = goToNextTab;
GamepadService.registerTabNavigation(
this,
previous: goToPreviousTab,
next: goToNextTab,
isActive: () => mounted && TickerMode.getValuesNotifier(context).value.enabled,
);
}
/// Dispose the [TabController] and clear gamepad callbacks.
/// Dispose the [TabController] and remove only this screen's callbacks.
/// Call from [dispose].
void disposeTabNavigation() {
GamepadService.unregisterTabNavigation(this);
tabController.removeListener(onTabChanged);
tabController.dispose();
GamepadService.onL1Pressed = null;
GamepadService.onR1Pressed = null;
}
void goToPreviousTab() {