除了
Chip
之外,如何制作一个onDeleted
来支持点击触发动作?
在我的代码中,添加手势处理程序会隐藏
onDeleted
点击触发:
/// A tappable chip
Widget _tappableChip({
/// The chip label
required String label,
/// Potential badge
int? badge,
/// The function to run when a tap occures
void Function()? onTap,
/// The function to remove the filter
void Function()? onDeleted,
}) {
return Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 5, 0),
child: GestureDetector(
onTap: onTap,
child: Chip(
onDeleted: onDeleted,
label: Text(label),
avatar: badge == null ? null : Badge.count(count: badge),
),
),
);
}
您可以在
onDelete
中调用
_tappableChip
中的两个方法
onDeleted: () {
onDeleted?.call();
onTap?.call();
}, // you follow this pattern