Created
April 14, 2021 10:56
-
-
Save nhancv/35d15339675e450b5ff667d53e7e77db to your computer and use it in GitHub Desktop.
Flutter simple shake animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class WShakeAnim extends StatelessWidget { | |
const WShakeAnim({ | |
Key key, | |
this.child, | |
this.offset = 100, | |
this.duration = const Duration(seconds: 1), | |
}) : super(key: key); | |
final Widget child; | |
final double offset; | |
final Duration duration; | |
@override | |
Widget build(BuildContext context) { | |
return TweenAnimationBuilder<double>( | |
child: child, | |
curve: Curves.elasticOut, | |
tween: Tween<double>(begin: 1.0, end: 0.0), | |
duration: duration, | |
builder: (BuildContext context, double value, Widget child) { | |
return Transform.translate( | |
offset: Offset(value * offset, 0.0), | |
child: child, | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment