From 17eb37cb376b4aaf2d93e74d7438ea45c533c2d7 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Mon, 13 Apr 2026 11:32:49 +0200 Subject: [PATCH] fix: back navigation on screens with no app bar actions close #854 --- lib/screens/focusable_detail_screen_mixin.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/screens/focusable_detail_screen_mixin.dart b/lib/screens/focusable_detail_screen_mixin.dart index 81fb8f36..69a05c0d 100644 --- a/lib/screens/focusable_detail_screen_mixin.dart +++ b/lib/screens/focusable_detail_screen_mixin.dart @@ -47,13 +47,20 @@ mixin FocusableDetailScreenMixin on State, GridFocu setState(() { isAppBarFocused = true; }); - actionBarKey.currentState?.getFocusNode(0).requestFocus(); + final state = actionBarKey.currentState; + if (state != null && getAppBarActions().isNotEmpty) { + state.getFocusNode(0).requestFocus(); + } // Scroll to top to show the app bar scrollController.animateTo(0, duration: const Duration(milliseconds: 200), curve: Curves.easeOut); } /// Handle BACK key from content - navigate to app bar and set flag to prevent PopScope exit void handleBackFromContent() { + if (getAppBarActions().isEmpty) { + if (mounted) Navigator.pop(context); + return; + } backHandledByKeyEvent = true; navigateToAppBar(); } @@ -83,8 +90,7 @@ mixin FocusableDetailScreenMixin on State, GridFocu return false; } - if (isAppBarFocused) { - // Already on app bar, allow exit + if (isAppBarFocused || getAppBarActions().isEmpty) { return true; } else { // Focus app bar first