FlippingRotationTransition<T> constructor

FlippingRotationTransition<T>({
  1. required Widget page,
  2. required bool isReversed,
})

Implementation

FlippingRotationTransition({required this.page, required this.isReversed})
    : super(
        pageBuilder: (context, animation, secondaryAnimation) => page,
        transitionsBuilder: (context, animation, secondaryAnimation, child) {
          final begin =
              isReversed ? const Offset(0.0, -1.0) : const Offset(0.0, 1.0);
          const end = Offset.zero;
          const curve = Curves.easeInOut;
          final tween =
              Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
          final offsetAnimation = animation.drive(tween);

          final rotationValue = Tween<double>(
            begin: 0.0,
            end: isReversed ? -pi : pi,
          ).animate(animation);

          final double finalRotation =
              animation.status == AnimationStatus.completed
                  ? 0.0
                  : rotationValue.value;

          return AnimatedBuilder(
            animation: animation,
            builder: (context, child) {
              return Transform(
                alignment: Alignment.center,
                transform: Matrix4.identity()
                  ..setEntry(3, 2, 0.001)
                  ..rotateX(finalRotation),
                child: SlideTransition(
                  position: offsetAnimation,
                  child: child,
                ),
              );
            },
            child: child,
          );
        },
      );