美文网首页
Flutter自定义路由样式

Flutter自定义路由样式

作者: 向上_d821 | 来源:发表于2019-07-14 16:30 被阅读0次
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<double> animation, Animation<double> secondaryAnimation) =>widget,
        transitionsBuilder:(BuildContext context, Animation<double> animation,
            Animation<double> 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<Offset>(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<Offset>(begin:Offset(-1.0,0.0),end: Offset(0.0, 0.0) ).animate(CurvedAnimation(parent: animation, curve: Curves.fastOutSlowIn)),
               child: child,
          );
        }

    );

}

相关文章

网友评论

      本文标题:Flutter自定义路由样式

      本文链接:https://www.haomeiwen.com/subject/etqikctx.html