PendulumPageTransition<T> constructor
PendulumPageTransition<T> ({
- required Widget page,
Implementation
PendulumPageTransition({required this.page})
: super(
pageBuilder: (context, animation, secondaryAnimation) => page,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(1.0, 0.0);
const end = Offset.zero;
const curve = Curves.easeInOut;
var tween =
Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
var offsetAnimation = animation.drive(tween);
const pendulumAmount =
15.0; // Adjust the pendulum amount as desired
final pendulumAnimation = Tween<double>(
begin: -pendulumAmount,
end: pendulumAmount,
).animate(animation);
return Transform.translate(
offset: Offset(
offsetAnimation.value.dx,
offsetAnimation.value.dy +
pendulumAnimation.value *
math.sin(animation.value * math.pi),
),
child: child,
);
},
);