From e9dfee68705b5575e470fd7369af44a50846616e Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sun, 22 Mar 2026 09:02:56 +0100 Subject: [PATCH] fix: profile select back button bypass close #737 --- lib/screens/profile/profile_switch_screen.dart | 7 +++++++ lib/widgets/focused_scroll_scaffold.dart | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/screens/profile/profile_switch_screen.dart b/lib/screens/profile/profile_switch_screen.dart index ff522c88..92f327d9 100644 --- a/lib/screens/profile/profile_switch_screen.dart +++ b/lib/screens/profile/profile_switch_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:material_symbols_icons/symbols.dart'; import 'package:provider/provider.dart'; import '../../models/plex_home_user.dart'; @@ -37,6 +38,11 @@ class _ProfileSwitchScreenState extends State { return PopScope( canPop: !widget.requireSelection || _allowPop, + onPopInvokedWithResult: (didPop, _) { + if (!didPop && widget.requireSelection) { + SystemNavigator.pop(); + } + }, child: Consumer( builder: (context, userProvider, child) { final users = userProvider.home?.users ?? []; @@ -44,6 +50,7 @@ class _ProfileSwitchScreenState extends State { return FocusedScrollScaffold( title: Text(t.screens.switchProfile), automaticallyImplyLeading: !widget.requireSelection, + onBackPressed: widget.requireSelection ? () => SystemNavigator.pop() : null, slivers: [ if (userProvider.isLoading) const SliverFillRemaining(child: Center(child: CircularProgressIndicator())) diff --git a/lib/widgets/focused_scroll_scaffold.dart b/lib/widgets/focused_scroll_scaffold.dart index 00c9e808..0415f73a 100644 --- a/lib/widgets/focused_scroll_scaffold.dart +++ b/lib/widgets/focused_scroll_scaffold.dart @@ -33,6 +33,11 @@ class FocusedScrollScaffold extends StatefulWidget { /// Defaults to true. final bool automaticallyImplyLeading; + /// Optional override for the back key handler. + /// When set, this callback is invoked instead of the default + /// [handleBackKeyNavigation] (which pops the current route). + final VoidCallback? onBackPressed; + const FocusedScrollScaffold({ super.key, required this.title, @@ -40,6 +45,7 @@ class FocusedScrollScaffold extends StatefulWidget { this.actions, this.pinned = true, this.automaticallyImplyLeading = true, + this.onBackPressed, }); @override @@ -75,7 +81,12 @@ class _FocusedScrollScaffoldState extends State { return Focus( canRequestFocus: false, - onKeyEvent: (_, event) => handleBackKeyNavigation(context, event), + onKeyEvent: (_, event) { + if (widget.onBackPressed != null) { + return handleBackKeyAction(event, widget.onBackPressed!); + } + return handleBackKeyNavigation(context, event); + }, child: FocusScope( node: _scopeNode, child: Scaffold(