Skip to content

Instantly share code, notes, and snippets.

@nhancv
Created April 14, 2021 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhancv/35d15339675e450b5ff667d53e7e77db to your computer and use it in GitHub Desktop.
Save nhancv/35d15339675e450b5ff667d53e7e77db to your computer and use it in GitHub Desktop.
Flutter simple shake animation
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