fix: android tv bottom sheet back button
This commit is contained in:
@@ -84,11 +84,32 @@ class SelectKeyUpSuppressor {
|
||||
/// the BACK key-up from propagating to the underlying screen.
|
||||
class BackKeyUpSuppressor {
|
||||
static bool _suppressBackUntilKeyUp = false;
|
||||
static bool _closedViaBackKey = false;
|
||||
|
||||
/// Mark that a modal is being closed via back key press.
|
||||
/// Call this before Navigator.pop() in back key handlers.
|
||||
static void markClosedViaBackKey() {
|
||||
_closedViaBackKey = true;
|
||||
}
|
||||
|
||||
/// Request suppression of back key-up events.
|
||||
/// Suppression is skipped if the modal was closed via back key
|
||||
/// (since the key-up already triggered the close).
|
||||
static void suppressBackUntilKeyUp() {
|
||||
if (_closedViaBackKey) {
|
||||
_closedViaBackKey = false;
|
||||
return;
|
||||
}
|
||||
_suppressBackUntilKeyUp = true;
|
||||
}
|
||||
|
||||
/// Clear any pending suppression. Call when opening a new modal
|
||||
/// to ensure stale suppression from previous closes doesn't affect it.
|
||||
static void clearSuppression() {
|
||||
_suppressBackUntilKeyUp = false;
|
||||
_closedViaBackKey = false;
|
||||
}
|
||||
|
||||
static bool consumeIfSuppressed(KeyEvent event) {
|
||||
if (!_suppressBackUntilKeyUp) return false;
|
||||
if (event.logicalKey.isBackKey) {
|
||||
|
||||
@@ -66,6 +66,8 @@ KeyEventResult handleBackKeyAction(KeyEvent event, VoidCallback onBack) {
|
||||
|
||||
if (event is KeyUpEvent) {
|
||||
BackKeyCoordinator.markHandled();
|
||||
// Mark that we're closing via back key so suppressBackUntilKeyUp() knows to skip
|
||||
BackKeyUpSuppressor.markClosedViaBackKey();
|
||||
onBack();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ ThemeData monoTheme({required bool dark, bool oled = false}) {
|
||||
textMuted: const Color(0x99111111),
|
||||
);
|
||||
|
||||
final isDark = dark || oled;
|
||||
|
||||
final buttonStyle = ButtonStyle(
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 18, vertical: 14)),
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
@@ -35,8 +37,6 @@ ThemeData monoTheme({required bool dark, bool oled = false}) {
|
||||
shape: const WidgetStatePropertyAll(StadiumBorder()),
|
||||
);
|
||||
|
||||
final isDark = dark || oled;
|
||||
|
||||
final base = ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: isDark ? Brightness.dark : Brightness.light,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../focus/input_mode_tracker.dart';
|
||||
import '../focus/dpad_navigator.dart';
|
||||
import '../focus/key_event_utils.dart';
|
||||
|
||||
/// A wrapper widget that provides autofocus functionality for bottom sheets.
|
||||
///
|
||||
@@ -29,6 +30,8 @@ class _FocusableBottomSheetState extends State<FocusableBottomSheet> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Clear any stale back key suppression from previous sheet closes
|
||||
BackKeyUpSuppressor.clearSuppression();
|
||||
_requestInitialFocus();
|
||||
}
|
||||
|
||||
@@ -61,13 +64,12 @@ class _FocusableBottomSheetState extends State<FocusableBottomSheet> {
|
||||
canRequestFocus: false,
|
||||
skipTraversal: true,
|
||||
onKeyEvent: (node, event) {
|
||||
// Handle select key suppression (for when sheet was opened via select key)
|
||||
if (SelectKeyUpSuppressor.consumeIfSuppressed(event)) {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (BackKeyUpSuppressor.consumeIfSuppressed(event)) {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
// Handle back key to close the bottom sheet
|
||||
return handleBackKeyNavigation(context, event);
|
||||
},
|
||||
child: widget.child,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user