如何制作一个同时处理 onDeleted 和点击它以触发额外操作的 Chip

问题描述 投票:0回答:1

除了

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),
        ),
      ),
    );
  }
flutter gesture-recognition
1个回答
0
投票

您可以在

onDelete
 中调用 
_tappableChip

中的两个方法
onDeleted: () {
   onDeleted?.call();
   onTap?.call();
  }, // you follow this pattern
© www.soinside.com 2019 - 2024. All rights reserved.