fix: profile select back button bypass

close #737
This commit is contained in:
edde746
2026-03-22 09:03:14 +01:00
parent 48e57fd375
commit e9dfee6870
2 changed files with 19 additions and 1 deletions
@@ -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<ProfileSwitchScreen> {
return PopScope(
canPop: !widget.requireSelection || _allowPop,
onPopInvokedWithResult: (didPop, _) {
if (!didPop && widget.requireSelection) {
SystemNavigator.pop();
}
},
child: Consumer<UserProfileProvider>(
builder: (context, userProvider, child) {
final users = userProvider.home?.users ?? [];
@@ -44,6 +50,7 @@ class _ProfileSwitchScreenState extends State<ProfileSwitchScreen> {
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()))
+12 -1
View File
@@ -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<FocusedScrollScaffold> {
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(