build method
渲染动画按钮Widget
返回值: Widget(带有不同动画表现的child)
示例:
Widget w = build(context);
Implementation
@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: _onTapDown,
child: AnimatedBuilder(
animation: _controller,
builder: (context, child) {
switch (widget.type) {
case 0:
// 无动画,直接显示child
return widget.child;
case 1:
// 弹跳动画(垂直方向移动)
return Transform.translate(
offset: _translateAnimation?.value ?? Offset.zero,
child: widget.child,
);
case 2:
// 摇摆动画(左右平滑移动)
return Transform.translate(
offset: Offset(
sin(_controller.value * 2 * pi) * 5,
0,
),
child: widget.child,
);
case 3:
// 脉冲动画(缩放)
return Transform.scale(
scale: _pulseAnimation?.value ?? 1.0,
child: widget.child,
);
case 4:
// 抖动动画(旋转抖动)
return Transform.rotate(
angle: _shakeAnimation?.value ?? 0.0,
child: widget.child,
);
case 5:
// 简单缩放动画
return Transform.scale(
scale: _scaleAnimation?.value ?? 1.0,
child: widget.child,
);
case 6:
// 组合动画(缩放+旋转)
return Transform(
alignment: Alignment.center,
transform: Matrix4.identity()
..scale(_scaleAnimation?.value ?? 1.0)
..rotateZ(_rotateAnimation?.value ?? 0.0),
child: widget.child,
);
default:
// 默认不做动画
return widget.child;
}
},
),
);
}