flutter 页面加载动画_flutter 导航页面转换动画效果

本文介绍了在Flutter中实现四种不同的页面转换动画:渐变效果、缩放效果、旋转+缩放效果以及滑动效果。通过CustomRouteJianBian、CustomRouteZoom、CustomRouteRotateZoom和CustomRouteSlide类,详细展示了如何自定义页面路由动画,为应用增加视觉吸引力。
摘要由CSDN通过智能技术生成

import 'package:flutter/material.dart';

//渐变效果

class CustomRouteJianBian extends PageRouteBuilder{

final Widget widget;

CustomRouteJianBian(this.widget)

:super(

transitionDuration:const Duration(seconds:1),

pageBuilder:(

BuildContext context,

Animation animation1,

Animation animation2){

return widget;

},

transitionsBuilder:(

BuildContext context,

Animation animation1,

Animation animation2,

Widget child){

return FadeTransition(

opacity: Tween(begin:0.0,end :2.0).animate(CurvedAnimation(

parent:animation1,

curve:Curves.fastOutSlowIn

)),

child: child,

);

}

);

}

//缩放效果

class CustomRouteZoom extends PageRouteBuilder{

final Widget widget;

CustomRouteZoom(this.widget)

:super(

transitionDuration:const Duration(seconds:1),

pageBuilder:(

BuildContext context,

Animation animation1,

Animation animation2){

return widget;

},

transitionsBuilder:(

BuildContext context,

Animation animation1,

Animation animation2,

Widget child){

return ScaleTransition(

scale:Tween(begin:0.0,end:1.0).animate(CurvedAnimation(

parent:animation1,

curve: Curves.fastOutSlowIn

)),

child:child

);

}

);

}

//旋转+缩放效果

class CustomRouteRotateZoom extends PageRouteBuilder{

final Widget widget;

CustomRouteRotateZoom(this.widget)

:super(

transitionDuration:const Duration(seconds:1),

pageBuilder:(

BuildContext context,

Animation animation1,

Animation animation2){

return widget;

},

transitionsBuilder:(

BuildContext context,

Animation animation1,

Animation animation2,

Widget child){

return RotationTransition(

turns:Tween(begin:0.0,end:1.0)

.animate(CurvedAnimation(

parent: animation1,

curve: Curves.fastOutSlowIn

)),

child:ScaleTransition(

scale:Tween(begin: 0.0,end:1.0)

.animate(CurvedAnimation(

parent: animation1,

curve:Curves.fastOutSlowIn

)),

child: child,

)

);

}

);

}

//滑动效果

class CustomRouteSlide extends PageRouteBuilder {

final Widget widget;

CustomRouteSlide(this.widget)

:super(

transitionDuration: const Duration(seconds: 1),

pageBuilder: (BuildContext context,

Animation animation1,

Animation animation2) {

return widget;

},

transitionsBuilder: (BuildContext context,

Animation animation1,

Animation animation2,

Widget child) {

return SlideTransition(

position: Tween(

begin: Offset(-1.0, 0.0),

end: Offset(0.0, 0.0)

)

.animate(CurvedAnimation(

parent: animation1,

curve: Curves.fastOutSlowIn

)),

child: child,

);

}

);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值