Flutter自定义路由样式

import 'package:flutter/material.dart';
 //创建的类需要继承 PageRouteBuilder ,重写方法
class CustomRoute extends PageRouteBuilder{
    final Widget widget;

  CustomRoute(this.widget)
      :super(
        transitionDuration:const Duration(milliseconds: 1000),
        pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) =>widget,
        transitionsBuilder:(BuildContext context, Animation animation,
            Animation secondaryAnimation, Widget child){
//          //淡出渐变过渡路由
//          return FadeTransition(
//              opacity: Tween(begin: 0.0,end: 1.0).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
//              child: child,
//          );
//          //比例转换路由
//        return ScaleTransition(
//            scale: Tween(begin: 0.0,end: 1.0).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
//            child: child,
//          );
        //  //旋转+比例转换路由
//          return RotationTransition(
//              turns: Tween(begin: -1.0,end: 1.0).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
//            child: ScaleTransition(
//                scale: Tween(begin: 0.0,end: 1.0).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
//              child: child,
//            ),
//          );
//           //幻灯片路由(上下滑动)
//          return SlideTransition(
//              position: Tween(begin:Offset(0.0,-1.0),end: Offset(0.0, 0.0) ).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
//               child: child,
//          );
          //幻灯片路由(左右滑动)
          return SlideTransition(
              position: Tween(begin:Offset(-1.0,0.0),end: Offset(0.0, 0.0) ).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
               child: child,
          );
        }

    );

}

你可能感兴趣的:(Flutter自定义路由样式)