From 65811cd0b2bfeeee3a48bb887287f5eaa38bc485 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Sun, 7 Dec 2025 22:51:55 +0100 Subject: [PATCH] fix: add missing context menu --- lib/widgets/hub_section.dart | 43 ++++++++++++------------------------ 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/lib/widgets/hub_section.dart b/lib/widgets/hub_section.dart index 7153576c..be8e4fea 100644 --- a/lib/widgets/hub_section.dart +++ b/lib/widgets/hub_section.dart @@ -223,13 +223,13 @@ class HubSectionState extends State { return KeyEventResult.ignored; } - /// Context menu keys for each item to trigger long press actions - final Map> _itemWrapperKeys = {}; + /// GlobalKeys for MediaCards to access their state (for context menu) + final Map> _mediaCardKeys = {}; - GlobalKey<_LockedHubItemWrapperState> _getItemWrapperKey(int index) { - return _itemWrapperKeys.putIfAbsent( + GlobalKey _getMediaCardKey(int index) { + return _mediaCardKeys.putIfAbsent( index, - () => GlobalKey<_LockedHubItemWrapperState>(), + () => GlobalKey(), ); } @@ -240,8 +240,7 @@ class HubSectionState extends State { } void _showContextMenuForCurrentItem() { - // Trigger long press on the wrapper which will bubble to MediaContextMenu - _itemWrapperKeys[_focusedIndex]?.currentState?.triggerLongPress(); + _mediaCardKeys[_focusedIndex]?.currentState?.showContextMenu(); } Future _navigateToItem(dynamic item) async { @@ -345,15 +344,12 @@ class HubSectionState extends State { return Padding( padding: const EdgeInsets.symmetric(horizontal: 2), child: _LockedHubItemWrapper( - key: _getItemWrapperKey(index), isFocused: isItemFocused, onTap: () => _onItemTapped(index), - onLongPress: () { - // Long press on item - this will be caught by - // MediaContextMenu inside MediaCard - }, + onLongPress: () => + _mediaCardKeys[index]?.currentState?.showContextMenu(), child: MediaCard( - key: Key(item.ratingKey), + key: _getMediaCardKey(index), item: item, width: cardWidth, height: posterHeight, @@ -397,38 +393,27 @@ class HubSectionState extends State { } /// Wrapper that provides visual focus decoration without using Flutter's focus system. -class _LockedHubItemWrapper extends StatefulWidget { +class _LockedHubItemWrapper extends StatelessWidget { final bool isFocused; final Widget child; final VoidCallback? onTap; final VoidCallback? onLongPress; const _LockedHubItemWrapper({ - super.key, required this.isFocused, required this.child, this.onTap, this.onLongPress, }); - @override - State<_LockedHubItemWrapper> createState() => _LockedHubItemWrapperState(); -} - -class _LockedHubItemWrapperState extends State<_LockedHubItemWrapper> { - /// Trigger long press programmatically (for D-pad context menu key) - void triggerLongPress() { - widget.onLongPress?.call(); - } - @override Widget build(BuildContext context) { return FocusBuilders.buildLockedFocusWrapper( context: context, - isFocused: widget.isFocused, - onTap: widget.onTap, - onLongPress: widget.onLongPress, - child: widget.child, + isFocused: isFocused, + onTap: onTap, + onLongPress: onLongPress, + child: child, ); } }