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
/*
* @author lsy
* @date 2019-10-14
**/
import 'package:flutter/material.dart';
enum RouteWay {
SCARE,
TRAN_RIGHT_TO_LEFT,
ALP,
}
class CustomRoute extends PageRouteBuilder {
final Widget widget;
RouteWay routeWay;
CustomRoute(this.widget, {RouteWay routeWay = RouteWay.TRAN_RIGHT_TO_LEFT})
: super(
// 设置过度时间
transitionDuration: Duration(milliseconds: 230),
// 构造器
pageBuilder: (
// 上下文和动画
BuildContext context,
Animation<double> animaton1,
Animation<double> animaton2,
) {
return widget;
},
transitionsBuilder: (
BuildContext context,
Animation<double> animaton1,
Animation<double> animaton2,
Widget child,
) {
// 渐变效果
if (routeWay.index == 2) {
return FadeTransition(
// 从0开始到1
opacity: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
// 传入设置的动画
parent: animaton1,
// 设置效果,快进漫出 这里有很多内置的效果
curve: Curves.fastOutSlowIn,
)),
child: child,
);
} else if (routeWay.index == 1) {
return SlideTransition(
position: Tween<Offset>(
begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
.animate(CurvedAnimation(
parent: animaton1, curve: Curves.fastOutSlowIn)),
child: child,
);
} else {
return ScaleTransition(
scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
parent: animaton1, curve: Curves.fastOutSlowIn)),
child: child,
);
}
// 旋转加缩放动画效果
// return RotationTransition(
// turns: Tween(begin: 0.0,end: 1.0)
// .animate(CurvedAnimation(
// parent: animaton1,
// curve: Curves.fastOutSlowIn,
// )),
// child: ScaleTransition(
// scale: Tween(begin: 0.0,end: 1.0)
// .animate(CurvedAnimation(
// parent: animaton1,
// curve: Curves.fastOutSlowIn
// )),
// child: child,
// ),
// );
});
}