首先介绍流程
1.在components文件夹中建立一个cartoon.dart
2.使用案例,在个人中心头像有个点击跳转页面功能(导入cartoon.dart动画组件,导入你要跳转dart页面)
关键代码:Navigator.push(context, CustomRouteSlide(DetailPage()));
CustomRouteSlide是动画效果就是cartoon.dart文件中定义的class,自己选择用哪个
DetailPage()就是你跳转的dart页面,
3.cartoon.dart代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | 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<double> animation1, Animation<double> animation2) { return widget; }, transitionsBuilder: (BuildContext context, Animation<double> animation1, Animation<double> 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<double> animation1, Animation<double> animation2) { return widget; }, transitionsBuilder: (BuildContext context, Animation<double> animation1, Animation<double> 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<double> animation1, Animation<double> animation2) { return widget; }, transitionsBuilder: (BuildContext context, Animation<double> animation1, Animation<double> 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(milliseconds: 500), pageBuilder: (BuildContext context, Animation<double> animation1, Animation<double> animation2) { return widget; }, transitionsBuilder: (BuildContext context, Animation<double> animation1, Animation<double> animation2, Widget child) { return SlideTransition( position: Tween<Offset>( begin: Offset(-1.0, 0.0), end: Offset(0.0, 0.0)) .animate(CurvedAnimation( parent: animation1, curve: Curves.fastOutSlowIn)), child: child, ); }); } |