-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathex11_page_transition1.dart
178 lines (168 loc) · 5.1 KB
/
ex11_page_transition1.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import 'package:flutter/material.dart';
import 'package:navigation_builder/navigation_builder.dart';
import 'package:states_rebuilder/scr/state_management/state_management.dart';
// Show case on how to customize page transition animation
void main() {
runApp(const MyApp());
}
final navigator = NavigationBuilder.create(
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return ScaleTransition(
scale: animation,
child: Transform.rotate(
angle: 1 - animation.value,
child: child,
),
);
},
transitionDuration: const Duration(milliseconds: 1000),
builder: (routerOutlet) {
return Padding(
padding: const EdgeInsets.all(32.0),
child: routerOutlet,
);
},
routes: {
'/': (data) => const HomePage(),
'/page1': (data) => const PageWidget(title: 'Page1'),
'/page2': (data) => const PageWidget(title: 'Page2'),
'/page3': (data) {
return RouteWidget(
builder: (_) {
return const PageWidget(title: 'Page3');
},
transitionsBuilder: NavigationBuilder.transitions.leftToRight(
duration: const Duration(milliseconds: 400),
),
);
},
'/page4': (data) => RouteWidget(
builder: (_) {
return const PageWidget(title: 'Page4');
},
transitionsBuilder: NavigationBuilder.transitions.none(),
),
'/page5': (data) => RouteWidget(
transitionsBuilder: NavigationBuilder.transitions.upToBottom(),
builder: (_) {
return const Page5Home();
},
routes: {
'/': (data) => Container(
color: Colors.red,
),
'/page51': (data) => Container(
color: Colors.green,
),
},
),
},
);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
theme: ThemeData.light(useMaterial3: false),
title: 'Books App',
routerConfig: navigator.routerConfig,
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home page')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => navigator.to('/page1'),
child: const Text('to page1 (rotation + scaling)'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => navigator.to('/page2'),
child: const Text('to page2 (rotation + scaling)'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => navigator.to('/page3'),
child: const Text('to page3 (slide left to right)'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => navigator.to('/page4'),
child: const Text('to page4 (no animation)'),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => navigator.to('/page5'),
child: const Text('to page5 (Nested Route: up to bottom)'),
),
],
),
),
);
}
}
class PageWidget extends StatelessWidget {
const PageWidget({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(
child: Text(title),
),
);
}
}
class Page5Home extends ReactiveStatelessWidget {
const Page5Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final location = context.routeData.location;
return Scaffold(
appBar: AppBar(
leading: BackButton(
onPressed: () => navigator.back(),
color: Theme.of(context).colorScheme.primary),
title: Row(
children: [
TextButton(
onPressed: () => navigator.to('/page5'),
child: Text(
'/Page5',
style: location == '/page5'
? const TextStyle(
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold,
)
: null,
),
),
TextButton(
onPressed: () => navigator.to('/page5/page51'),
child: Text(
'/Page5/page51',
style: location == '/page5/page51'
? const TextStyle(
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold,
)
: null,
),
),
],
),
backgroundColor: Colors.white,
),
body: context.routerOutlet,
);
}
}