TransitionX constructor

TransitionX({
  1. required Widget widget,
  2. TransitionType transitionType = TransitionType.fade,
  3. bool bounce = true,
  4. Curve curve = Curves.linear,
  5. Duration duration = TransitionX.animationDuration,
})

TransitionX animation constractor

Implementation

TransitionX({
  /// Destination widget
  required this.widget,

  /// Transition type
  this.transitionType = TransitionType.fade,

  /// Set Bounce
  this.bounce = true,

  /// Sets curve of animation type [TransitionType.slideToRightWithFade]
  this.curve = Curves.linear,

  /// Duration of animation
  this.duration = TransitionX.animationDuration,
}) : super(
        transitionDuration: duration,
        transitionsBuilder: (
          BuildContext context,
          Animation<double> animation,
          Animation<double> secAmination,
          Widget child,
        ) {
          if (bounce) {
            animation = CurvedAnimation(
                parent: animation, curve: Curves.elasticInOut);
          }
          switch (transitionType) {
            case TransitionType.bouncyScale:
              return ScaleTransition(
                alignment: Alignment.center,
                scale: animation,
                child: child,
              );
            case TransitionType.slideToBottom:
              return SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(0, -1),
                  end: Offset.zero,
                ).animate(animation),
                child: child,
              );
            case TransitionType.slideToTop:
              return SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(0, 1),
                  end: Offset.zero,
                ).animate(animation),
                child: child,
              );
            case TransitionType.slideToLeft:
              return SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(1, 0),
                  end: Offset.zero,
                ).animate(animation),
                child: child,
              );
            case TransitionType.slideToRight:
              return SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(-1, 0),
                  end: Offset.zero,
                ).animate(animation),
                child: child,
              );
            case TransitionType.slideToLeftWithFade:
              return SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(1.0, 0.0),
                  end: Offset.zero,
                ).animate(animation),
                child: FadeTransition(
                  opacity: animation,
                  child: SlideTransition(
                    position: Tween<Offset>(
                      begin: const Offset(1, 0),
                      end: Offset.zero,
                    ).animate(animation),
                    child: child,
                  ),
                ),
              );
            case TransitionType.slideToRightWithFade:
              return SlideTransition(
                position: Tween<Offset>(
                  begin: const Offset(-1.0, 0.0),
                  end: Offset.zero,
                ).animate(
                  CurvedAnimation(
                    parent: animation,
                    curve: curve,
                  ),
                ),
                child: FadeTransition(
                  opacity: animation,
                  child: SlideTransition(
                    position: Tween<Offset>(
                      begin: const Offset(-1, 0),
                      end: Offset.zero,
                    ).animate(animation),
                    child: child,
                  ),
                ),
              );
            default:
              return FadeTransition(opacity: animation, child: child);
          }
        },
        pageBuilder: (
          BuildContext context,
          Animation<double> animation,
          Animation<double> secAmination,
        ) {
          return widget;
        },
      );