-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnavigation.dart
119 lines (104 loc) · 4.32 KB
/
navigation.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import 'package:flutter/material.dart';
class Navigation {
static Future<Future<T?>> createRoute<T>(Widget destination, BuildContext context,
[AnimationEnum animationEnum = AnimationEnum.fromRight, Object payload = true]) async {
PageRouteBuilder<T> pageRoute;
Widget _safeArea(Widget child) => Container(
color: Color(0xFF0C2838),
child: child,
);
switch (animationEnum) {
case AnimationEnum.fadeIn:
pageRoute = PageRouteBuilder<T>(
settings: RouteSettings(arguments: payload),
transitionDuration: Duration(milliseconds: 500),
reverseTransitionDuration: Duration(milliseconds: 500),
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = 0.0;
var end = 1.0;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return FadeTransition(
opacity: animation.drive(tween),
child: _safeArea(child),
);
},
);
break;
case AnimationEnum.pageAscend:
pageRoute = PageRouteBuilder<T>(
settings: RouteSettings(arguments: payload),
transitionDuration: Duration(milliseconds: 500),
reverseTransitionDuration: Duration(milliseconds: 500),
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = Offset(0.0, 1.0);
var end = Offset.zero;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: _safeArea(child),
);
},
);
break;
case AnimationEnum.fromRight:
pageRoute = PageRouteBuilder<T>(
settings: RouteSettings(arguments: payload),
transitionDuration: Duration(milliseconds: 500),
reverseTransitionDuration: Duration(milliseconds: 500),
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = Offset(1.0, 0.0);
var end = Offset.zero;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: _safeArea(child),
);
},
);
break;
case AnimationEnum.fromLeft:
pageRoute = PageRouteBuilder<T>(
settings: RouteSettings(arguments: payload),
transitionDuration: Duration(milliseconds: 500),
reverseTransitionDuration: Duration(milliseconds: 500),
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = Offset(-1.0, 0.0);
var end = Offset.zero;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: _safeArea(child),
);
},
);
break;
default:
pageRoute = PageRouteBuilder<T>(
settings: RouteSettings(arguments: payload),
transitionDuration: Duration(milliseconds: 500),
reverseTransitionDuration: Duration(milliseconds: 500),
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = 0.0;
var end = 1.0;
var curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return FadeTransition(
opacity: animation.drive(tween),
child: _safeArea(child),
);
},
);
}
return Navigator.of(context).push(pageRoute);
}
}
enum AnimationEnum { pageAscend, fadeIn, fromRight, fromLeft }