Files
tuiche/lib/component/tool/ClickableContainer.dart
2025-04-16 14:27:10 +08:00

46 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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, // 内容自适应
),
),
),
),
);
}
}