/// A tap with a primary button has occurred.
///
/// This triggers when the tap gesture wins. If the tap gesture did not win,
/// [onTapCancel] is called instead.
///
/// See also:
///
/// * [kPrimaryButton], the button this callback responds to.
/// * [onTapUp], which is called at the same time but includes details
/// regarding the pointer position.
final GestureTapCallback? onTap;
/// Signature for when a tap has occurred.
///
/// See also:
///
/// * [GestureDetector.onTap], which matches this signature.
/// * [TapGestureRecognizer], which uses this signature in one of its callbacks.
typedef GestureTapCallback = void Function();
这样我们就可以通过为 Cell 添加一个回调类型的成员,来传入事件。
class MomentHomeCell extends StatelessWidget {
final String title;
final String? subTitle;
final String imageName;
final String? subImageName;
final GestureTapCallback? didSelected;
MomentHomeCell(
{required this.title,
this.subTitle,
required this.imageName,
this.subImageName,
this.didSelected});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: didSelected,
child: ...,
);
}
}