更新
This commit is contained in:
@@ -5,7 +5,9 @@ class CustomCard extends StatefulWidget {
|
||||
final VoidCallback onTap; // 点击回调
|
||||
final List<Color> colors; // 背景颜色列表
|
||||
final Widget child; // 子组件
|
||||
final String title;
|
||||
final String title; // 标题
|
||||
final bool enableAnimation; // 是否启用动画效果
|
||||
final bool enableGradient; // 是否启用渐变
|
||||
|
||||
const CustomCard({
|
||||
Key? key,
|
||||
@@ -14,6 +16,8 @@ class CustomCard extends StatefulWidget {
|
||||
required this.colors,
|
||||
required this.child,
|
||||
required this.title,
|
||||
this.enableAnimation = true, // 默认启用动画效果
|
||||
this.enableGradient = true, // 默认启用渐变效果
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -60,7 +64,7 @@ class _CustomCardState extends State<CustomCard>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isGradient = widget.colors.length > 1;
|
||||
final bool isGradient = widget.enableGradient && widget.colors.length > 1; // 只有启用渐变时,才使用渐变
|
||||
final Color baseColor = widget.colors.first;
|
||||
|
||||
return Material(
|
||||
@@ -69,26 +73,42 @@ class _CustomCardState extends State<CustomCard>
|
||||
child: GestureDetector(
|
||||
onTapDown: _handleTap,
|
||||
behavior: HitTestBehavior.translucent, // 关键:让空白区域也能点击
|
||||
child: AnimatedScale(
|
||||
scale: _scale,
|
||||
duration: _animationDuration,
|
||||
curve: Curves.easeInOut,
|
||||
child: Ink(
|
||||
key: _inkKey,
|
||||
decoration: BoxDecoration(
|
||||
color: isGradient ? null : baseColor,
|
||||
gradient: isGradient
|
||||
? LinearGradient(
|
||||
colors: widget.colors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
child: widget.enableAnimation // 判断是否启用动画
|
||||
? AnimatedScale(
|
||||
scale: _scale,
|
||||
duration: _animationDuration,
|
||||
curve: Curves.easeInOut,
|
||||
child: Ink(
|
||||
key: _inkKey,
|
||||
decoration: BoxDecoration(
|
||||
color: isGradient ? null : baseColor,
|
||||
gradient: isGradient
|
||||
? LinearGradient(
|
||||
colors: widget.colors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
)
|
||||
: Ink(
|
||||
key: _inkKey,
|
||||
decoration: BoxDecoration(
|
||||
color: isGradient ? null : baseColor,
|
||||
gradient: isGradient
|
||||
? LinearGradient(
|
||||
colors: widget.colors,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user