import 'package:flutter/material.dart'; class ClickableContainer extends StatelessWidget { final Color backgroundColor; // 容器背景色 final Color highlightColor; // 点击时背景色 final EdgeInsetsGeometry padding; // 内部间距 final VoidCallback onTap; // 点击回调 final Widget child; // 子组件 final double borderRadius; // 容器圆角(可选,默认为0) const ClickableContainer({ Key? key, required this.backgroundColor, required this.highlightColor, required this.padding, required this.onTap, required this.child, this.borderRadius = 0, // 默认无圆角 }) : super(key: key); @override Widget build(BuildContext context) { return GestureDetector( onTap: onTap, child: Material( color: Colors.transparent, child: Ink( decoration: BoxDecoration( color: backgroundColor, borderRadius: BorderRadius.circular(borderRadius), ), child: InkWell( borderRadius: BorderRadius.circular(borderRadius), onTap: onTap, splashColor: highlightColor.withOpacity(0.3), // 点击时的波纹效果 child: Padding( padding: padding, child: child, // 内容自适应 ), ), ), ), ); } }