SwingPageTransition<T> constructor

SwingPageTransition<T>({
  1. required Widget page,
})

Implementation

SwingPageTransition({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 swingAmount = 15.0; // Adjust the swing amount as desired
          final swingAnimation = Tween<double>(
            begin: -swingAmount,
            end: swingAmount,
          ).animate(animation);

          return Transform.translate(
            offset: Offset(
              offsetAnimation.value.dx +
                  swingAnimation.value * math.sin(animation.value * math.pi),
              offsetAnimation.value.dy,
            ),
            child: child,
          );
        },
      );