diff --git a/app/lib/features/geckoview/features/tabs/presentation/widgets/container_chips.dart b/app/lib/features/geckoview/features/tabs/presentation/widgets/container_chips.dart index a9766d6f..79987c9a 100644 --- a/app/lib/features/geckoview/features/tabs/presentation/widgets/container_chips.dart +++ b/app/lib/features/geckoview/features/tabs/presentation/widgets/container_chips.dart @@ -44,6 +44,7 @@ class ContainerChips extends HookConsumerWidget { final bool Function(ContainerDataWithCount)? containerFilter; final void Function(ContainerDataWithCount?)? onSelected; final void Function(ContainerDataWithCount)? onDeleted; + final void Function(ContainerDataWithCount)? onLongPress; final ValueListenable? searchTextListenable; @@ -51,6 +52,7 @@ class ContainerChips extends HookConsumerWidget { required this.selectedContainer, required this.onSelected, required this.onDeleted, + this.onLongPress, this.containerFilter, this.searchTextListenable, this.displayMenu = true, @@ -197,6 +199,7 @@ class ContainerChips extends HookConsumerWidget { selectedItem: selectedContainer, onSelected: onSelected, onDeleted: onDeleted, + onLongPress: onLongPress, ), ), if (displayMenu) diff --git a/app/lib/presentation/widgets/selectable_chips.dart b/app/lib/presentation/widgets/selectable_chips.dart index 0032ec98..8544e8a4 100644 --- a/app/lib/presentation/widgets/selectable_chips.dart +++ b/app/lib/presentation/widgets/selectable_chips.dart @@ -19,6 +19,7 @@ */ import 'package:fading_scroll/fading_scroll.dart'; import 'package:flutter/material.dart'; +import 'package:nullability/nullability.dart'; class _BadgeWrapper extends StatelessWidget { final Widget child; @@ -39,6 +40,20 @@ class _BadgeWrapper extends StatelessWidget { } } +class _GestureWrapper extends StatelessWidget { + final Widget child; + final GestureLongPressCallback? onLongPress; + + const _GestureWrapper({required this.child, this.onLongPress}); + + @override + Widget build(BuildContext context) { + return onLongPress != null + ? InkWell(onLongPress: onLongPress, child: child) + : child; + } +} + class SelectableChips extends StatelessWidget { final List availableItems; final List prefixListItems; @@ -56,6 +71,7 @@ class SelectableChips extends StatelessWidget { final void Function(T item)? onSelected; final void Function(T item)? onDeleted; + final void Function(T item)? onLongPress; const SelectableChips({ required this.itemId, @@ -71,6 +87,7 @@ class SelectableChips extends StatelessWidget { this.deleteIcon = true, this.onSelected, this.onDeleted, + this.onLongPress, super.key, }); @@ -110,26 +127,32 @@ class SelectableChips extends StatelessWidget { padding: const EdgeInsets.only(right: 8.0, top: 4.0), child: _BadgeWrapper( count: itemBadgeCount?.call(item), - child: FilterChip( - selected: - selectedItem != null && - itemId(item) == itemId(selectedItem as S), - showCheckmark: false, - onSelected: (value) { - if (value) { - onSelected?.call(item); - } else { - onDeleted?.call(item); - } - }, - onDeleted: deleteIcon - ? () { - onDeleted?.call(item); - } - : null, - label: itemLabel.call(item), - avatar: itemAvatar?.call(item), - tooltip: itemTooltip?.call(item), + child: _GestureWrapper( + onLongPress: onLongPress.mapNotNull( + (callback) => + () => callback(item), + ), + child: FilterChip( + selected: + selectedItem != null && + itemId(item) == itemId(selectedItem as S), + showCheckmark: false, + onSelected: (value) { + if (value) { + onSelected?.call(item); + } else { + onDeleted?.call(item); + } + }, + onDeleted: deleteIcon + ? () { + onDeleted?.call(item); + } + : null, + label: itemLabel.call(item), + avatar: itemAvatar?.call(item), + tooltip: itemTooltip?.call(item), + ), ), ), );