Animated-Text-Kit
Animated-Text-Kit copied to clipboard
Shaking text
It would be nice to have a shaking text effect (for friendly error message for example)
ok, I've managed to get it but I don't have the time to make a proper PR. Feel free to take it.
class ShakingAnimatedText extends AnimatedText {
int numberOfShakes;
int shakeOffset;
double _animationValue = 0;
ShakingAnimatedText(
String text, {
TextAlign textAlign = TextAlign.start,
TextStyle? textStyle,
Duration duration = const Duration(milliseconds: 500),
this.numberOfShakes = 2,
this.shakeOffset = 7,
}) : super(
text: text,
textAlign: textAlign,
textStyle: textStyle,
duration: duration,
);
@override
Widget animatedBuilder(BuildContext context, Widget? child) {
final sineValue = sin(numberOfShakes * 2 * pi * _animationValue);
return Transform.translate(
offset: Offset(sineValue * shakeOffset, 0),
child: child,
);
}
@override
void initAnimation(AnimationController controller) {
controller.addListener(() {
_animationValue = controller.value;
});
}
}