@@ -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()))
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user