我正在尝试开发一种类似于涟漪的效果,但它非常平滑和令人愉快。我已经尝试开发它使用动画和自定义油漆,但它不变成相同的。有没有人能达到这样的效果?你能帮我找到任何可能的方法吗?
谢谢你!
这是我使用mixin动画的代码:
class CircleAnimateWidget extends StatefulWidget {
final double sizeMin;
final double sizeMax;
final double containerSize;
final int duration;
final int reverseDuration;
const CircleAnimateWidget({super.key, required this.sizeMin, required this.duration, required this.sizeMax, required this.containerSize, required this.reverseDuration});
@override
State<StatefulWidget> createState() {
return _State();
}
}
class _State extends State<CircleAnimateWidget>
with TickerProviderStateMixin {
late Animation _sizeAnimation;
late AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: widget.duration),
reverseDuration: Duration(milliseconds: widget.reverseDuration));
_sizeAnimation = Tween(begin: widget.sizeMin, end: widget.sizeMax).animate(CurvedAnimation(
curve: Curves.elasticOut,
reverseCurve: Curves.ease,
parent: _animationController));
_animationController.addStatusListener(
(AnimationStatus status) async {
if (status == AnimationStatus.completed) {
await Future.delayed(const Duration(milliseconds: 50));
_animationController.reverse();
} else if (status == AnimationStatus.dismissed) {
_animationController.forward();
}
},
);
_animationController.forward();
}
@override
void dispose() {
_animationController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return Container(
width: widget.containerSize,
height: widget.containerSize,
alignment: Alignment.center,
child: SizedBox(
width: _sizeAnimation.value,
height: _sizeAnimation.value,
child: CircleAvatar(
backgroundColor: Colors.green.withOpacity(0.3),
child: const SizedBox(),
),
),
);
},
),
);
}
}
并将其放入堆栈:
[Positioned(
child: CircleAnimateWidget(
sizeMin: maxCircleSize - 20,
sizeMax: maxCircleSize,
duration: 1500,
reverseDuration: 500,
containerSize: maxCircleSize + 50,
)
),
Positioned(
child: CircleAnimateWidget(
sizeMin: maxCircleSize - 50,
sizeMax: maxCircleSize - 30,
duration: 1500,
reverseDuration: 500,
containerSize: maxCircleSize + 50,
)
),
Positioned(
child: CircleAnimateWidget(
sizeMin: maxCircleSize - 90,
sizeMax: maxCircleSize - 60,
duration: 1500,
reverseDuration: 500,
containerSize: maxCircleSize + 50,
)
)]
1条答案
按热度按时间tnkciper1#
你可以像这样使用自定义的
CustomPainter
:并将其用于:
注意它使用dart v3.0,如果你有旧版本,用一些只包含两个数据字段的
Ring
类示例替换ringData
的记录:Curve
和Color
编辑
如果你不想使用
CustomPaint
,你可以使用三个ScaleTransition
: