Skip to content

Commit b887619

Browse files
committed
Create NoAnimationPageTransitionsBuilder
- Replace Route builder with NoAnimationPageTransitionsBuilder.
1 parent 4079e0d commit b887619

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

lib/main.dart

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
33
// ignore: depend_on_referenced_packages
44
import 'package:flutter_web_plugins/url_strategy.dart';
55
import 'package:minimal/pages/pages.dart';
6-
import 'package:minimal/routes.dart';
6+
import 'package:minimal/utils/no_animation_page_transitions_builder.dart';
77
import 'package:responsive_framework/responsive_framework.dart';
88

99
void main() {
@@ -44,6 +44,16 @@ class MyApp extends StatelessWidget {
4444
final Uri uri = Uri.parse(settings.name ?? '/');
4545
return buildPage(path: uri.path, queryParams: uri.queryParameters);
4646
},
47+
theme: ThemeData(
48+
pageTransitionsTheme: PageTransitionsTheme(
49+
builders: {
50+
TargetPlatform.fuchsia: NoAnimationPageTransitionsBuilder(),
51+
TargetPlatform.linux: NoAnimationPageTransitionsBuilder(),
52+
TargetPlatform.macOS: NoAnimationPageTransitionsBuilder(),
53+
TargetPlatform.windows: NoAnimationPageTransitionsBuilder(),
54+
},
55+
),
56+
),
4757
debugShowCheckedModeBanner: false,
4858
);
4959
}
@@ -52,25 +62,26 @@ class MyApp extends StatelessWidget {
5262
// Navigate using the page name, `Navigator.pushNamed(context, ListPage.name)`.
5363
Route<dynamic> buildPage(
5464
{required String path, Map<String, String> queryParams = const {}}) {
55-
return Routes.noAnimation(
56-
settings: RouteSettings(
57-
name: (path.startsWith('/') == false) ? '/$path' : path),
58-
builder: (context) {
59-
String pathName =
60-
path != '/' && path.startsWith('/') ? path.substring(1) : path;
61-
return switch (pathName) {
62-
'/' || ListPage.name => const ListPage(),
63-
PostPage.name =>
64-
// Breakpoints can be nested.
65-
// Here's an example of custom "per-page" breakpoints.
66-
const ResponsiveBreakpoints(breakpoints: [
67-
Breakpoint(start: 0, end: 480, name: MOBILE),
68-
Breakpoint(start: 481, end: 1200, name: TABLET),
69-
Breakpoint(start: 1201, end: double.infinity, name: DESKTOP),
70-
], child: PostPage()),
71-
TypographyPage.name => const TypographyPage(),
72-
_ => const SizedBox.shrink(),
73-
};
74-
});
65+
return PageRouteBuilder(
66+
settings: RouteSettings(
67+
name: (path.startsWith('/') == false) ? '/$path' : path),
68+
pageBuilder: (context, animation, secondaryAnimation) {
69+
String pathName =
70+
path != '/' && path.startsWith('/') ? path.substring(1) : path;
71+
return switch (pathName) {
72+
'/' || ListPage.name => const ListPage(),
73+
PostPage.name =>
74+
// Breakpoints can be nested.
75+
// Here's an example of custom "per-page" breakpoints.
76+
const ResponsiveBreakpoints(breakpoints: [
77+
Breakpoint(start: 0, end: 480, name: MOBILE),
78+
Breakpoint(start: 481, end: 1200, name: TABLET),
79+
Breakpoint(start: 1201, end: double.infinity, name: DESKTOP),
80+
], child: PostPage()),
81+
TypographyPage.name => const TypographyPage(),
82+
_ => const SizedBox.shrink(),
83+
};
84+
},
85+
);
7586
}
7687
}

lib/main_advanced.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MyApp extends StatelessWidget {
3535
// behavior for a page.
3636
onGenerateRoute: (RouteSettings settings) {
3737
// A custom `fadeThrough` route transition animation.
38-
return Routes.fadeThrough(
38+
return Routes.noAnimation(
3939
settings: settings,
4040
builder: (context) {
4141
// Wrap widgets with another widget based on the route.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/material.dart';
2+
3+
class NoAnimationPageTransitionsBuilder extends PageTransitionsBuilder {
4+
@override
5+
Widget buildTransitions<T>(
6+
PageRoute<T> route,
7+
BuildContext context,
8+
Animation<double> animation,
9+
Animation<double> secondaryAnimation,
10+
Widget child,
11+
) {
12+
return child;
13+
}
14+
}

0 commit comments

Comments
 (0)