support long press gesture
This commit is contained in:
@@ -44,6 +44,7 @@ class ContainerChips extends HookConsumerWidget {
|
|||||||
final bool Function(ContainerDataWithCount)? containerFilter;
|
final bool Function(ContainerDataWithCount)? containerFilter;
|
||||||
final void Function(ContainerDataWithCount?)? onSelected;
|
final void Function(ContainerDataWithCount?)? onSelected;
|
||||||
final void Function(ContainerDataWithCount)? onDeleted;
|
final void Function(ContainerDataWithCount)? onDeleted;
|
||||||
|
final void Function(ContainerDataWithCount)? onLongPress;
|
||||||
|
|
||||||
final ValueListenable<TextEditingValue>? searchTextListenable;
|
final ValueListenable<TextEditingValue>? searchTextListenable;
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class ContainerChips extends HookConsumerWidget {
|
|||||||
required this.selectedContainer,
|
required this.selectedContainer,
|
||||||
required this.onSelected,
|
required this.onSelected,
|
||||||
required this.onDeleted,
|
required this.onDeleted,
|
||||||
|
this.onLongPress,
|
||||||
this.containerFilter,
|
this.containerFilter,
|
||||||
this.searchTextListenable,
|
this.searchTextListenable,
|
||||||
this.displayMenu = true,
|
this.displayMenu = true,
|
||||||
@@ -197,6 +199,7 @@ class ContainerChips extends HookConsumerWidget {
|
|||||||
selectedItem: selectedContainer,
|
selectedItem: selectedContainer,
|
||||||
onSelected: onSelected,
|
onSelected: onSelected,
|
||||||
onDeleted: onDeleted,
|
onDeleted: onDeleted,
|
||||||
|
onLongPress: onLongPress,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (displayMenu)
|
if (displayMenu)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
import 'package:fading_scroll/fading_scroll.dart';
|
import 'package:fading_scroll/fading_scroll.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:nullability/nullability.dart';
|
||||||
|
|
||||||
class _BadgeWrapper extends StatelessWidget {
|
class _BadgeWrapper extends StatelessWidget {
|
||||||
final Widget child;
|
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<T extends S, S, K> extends StatelessWidget {
|
class SelectableChips<T extends S, S, K> extends StatelessWidget {
|
||||||
final List<T> availableItems;
|
final List<T> availableItems;
|
||||||
final List<Widget> prefixListItems;
|
final List<Widget> prefixListItems;
|
||||||
@@ -56,6 +71,7 @@ class SelectableChips<T extends S, S, K> extends StatelessWidget {
|
|||||||
|
|
||||||
final void Function(T item)? onSelected;
|
final void Function(T item)? onSelected;
|
||||||
final void Function(T item)? onDeleted;
|
final void Function(T item)? onDeleted;
|
||||||
|
final void Function(T item)? onLongPress;
|
||||||
|
|
||||||
const SelectableChips({
|
const SelectableChips({
|
||||||
required this.itemId,
|
required this.itemId,
|
||||||
@@ -71,6 +87,7 @@ class SelectableChips<T extends S, S, K> extends StatelessWidget {
|
|||||||
this.deleteIcon = true,
|
this.deleteIcon = true,
|
||||||
this.onSelected,
|
this.onSelected,
|
||||||
this.onDeleted,
|
this.onDeleted,
|
||||||
|
this.onLongPress,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -110,26 +127,32 @@ class SelectableChips<T extends S, S, K> extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.only(right: 8.0, top: 4.0),
|
padding: const EdgeInsets.only(right: 8.0, top: 4.0),
|
||||||
child: _BadgeWrapper(
|
child: _BadgeWrapper(
|
||||||
count: itemBadgeCount?.call(item),
|
count: itemBadgeCount?.call(item),
|
||||||
child: FilterChip(
|
child: _GestureWrapper(
|
||||||
selected:
|
onLongPress: onLongPress.mapNotNull(
|
||||||
selectedItem != null &&
|
(callback) =>
|
||||||
itemId(item) == itemId(selectedItem as S),
|
() => callback(item),
|
||||||
showCheckmark: false,
|
),
|
||||||
onSelected: (value) {
|
child: FilterChip(
|
||||||
if (value) {
|
selected:
|
||||||
onSelected?.call(item);
|
selectedItem != null &&
|
||||||
} else {
|
itemId(item) == itemId(selectedItem as S),
|
||||||
onDeleted?.call(item);
|
showCheckmark: false,
|
||||||
}
|
onSelected: (value) {
|
||||||
},
|
if (value) {
|
||||||
onDeleted: deleteIcon
|
onSelected?.call(item);
|
||||||
? () {
|
} else {
|
||||||
onDeleted?.call(item);
|
onDeleted?.call(item);
|
||||||
}
|
}
|
||||||
: null,
|
},
|
||||||
label: itemLabel.call(item),
|
onDeleted: deleteIcon
|
||||||
avatar: itemAvatar?.call(item),
|
? () {
|
||||||
tooltip: itemTooltip?.call(item),
|
onDeleted?.call(item);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
label: itemLabel.call(item),
|
||||||
|
avatar: itemAvatar?.call(item),
|
||||||
|
tooltip: itemTooltip?.call(item),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user