Skip to content

Commit 9b94e15

Browse files
committed
Disable Route Transition Animation
1 parent f7b996c commit 9b94e15

File tree

3 files changed

+54
-36
lines changed

3 files changed

+54
-36
lines changed

lib/main.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +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';
67
import 'package:responsive_framework/responsive_framework.dart';
78

89
void main() {
@@ -49,9 +50,9 @@ class MyApp extends StatelessWidget {
4950

5051
// onGenerateRoute route switcher.
5152
// Navigate using the page name, `Navigator.pushNamed(context, ListPage.name)`.
52-
PageRoute buildPage(
53+
Route<dynamic> buildPage(
5354
{required String path, Map<String, String> queryParams = const {}}) {
54-
return MaterialPageRoute(
55+
return Routes.noAnimation(
5556
settings: RouteSettings(
5657
name: (path.startsWith('/') == false) ? '/$path' : path),
5758
builder: (context) {

lib/main_advanced.dart

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,40 @@ class MyApp extends StatelessWidget {
3535
// behavior for a page.
3636
onGenerateRoute: (RouteSettings settings) {
3737
// A custom `fadeThrough` route transition animation.
38-
return Routes.fadeThrough(settings, (context) {
39-
// Wrap widgets with another widget based on the route.
40-
// Wrap the page with the ResponsiveScaledBox for desired pages.
41-
return ConditionalRouteWidget(
42-
routesExcluded: const [
43-
TypographyPage.name
44-
], // Excluding a page from AutoScale.
45-
builder: (context, child) => MaxWidthBox(
46-
// A widget that limits the maximum width.
47-
// This is used to create a gutter area on either side of the content.
48-
maxWidth: 1200,
49-
background: Container(color: const Color(0xFFF5F5F5)),
50-
child: ResponsiveScaledBox(
51-
// ResponsiveScaledBox renders its child with a FittedBox set to the `width` value.
52-
// Set the fixed width value based on the active breakpoint.
53-
width: ResponsiveValue<double>(context,
54-
conditionalValues: [
55-
const Condition.equals(name: MOBILE, value: 450),
56-
const Condition.between(
57-
start: 800, end: 1100, value: 800),
58-
const Condition.between(
59-
start: 1000, end: 1200, value: 1000),
60-
// There are no conditions for width over 1200
61-
// because the `maxWidth` is set to 1200 via the MaxWidthBox.
62-
]).value,
63-
child: child!),
64-
),
65-
child: BouncingScrollWrapper.builder(
66-
context, buildPage(settings.name ?? ''),
67-
dragWithMouse: true));
68-
});
38+
return Routes.fadeThrough(
39+
settings: settings,
40+
builder: (context) {
41+
// Wrap widgets with another widget based on the route.
42+
// Wrap the page with the ResponsiveScaledBox for desired pages.
43+
return ConditionalRouteWidget(
44+
routesExcluded: const [
45+
TypographyPage.name
46+
], // Excluding a page from AutoScale.
47+
builder: (context, child) => MaxWidthBox(
48+
// A widget that limits the maximum width.
49+
// This is used to create a gutter area on either side of the content.
50+
maxWidth: 1200,
51+
background: Container(color: const Color(0xFFF5F5F5)),
52+
child: ResponsiveScaledBox(
53+
// ResponsiveScaledBox renders its child with a FittedBox set to the `width` value.
54+
// Set the fixed width value based on the active breakpoint.
55+
width: ResponsiveValue<double>(context,
56+
conditionalValues: [
57+
const Condition.equals(
58+
name: MOBILE, value: 450),
59+
const Condition.between(
60+
start: 800, end: 1100, value: 800),
61+
const Condition.between(
62+
start: 1000, end: 1200, value: 1000),
63+
// There are no conditions for width over 1200
64+
// because the `maxWidth` is set to 1200 via the MaxWidthBox.
65+
]).value,
66+
child: child!),
67+
),
68+
child: BouncingScrollWrapper.builder(
69+
context, buildPage(settings.name ?? ''),
70+
dragWithMouse: true));
71+
});
6972
},
7073
debugShowCheckedModeBanner: false,
7174
);

lib/routes.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ import 'package:animations/animations.dart';
22
import 'package:flutter/widgets.dart';
33

44
class Routes {
5-
static Route<T> fadeThrough<T>(RouteSettings settings, WidgetBuilder page,
6-
{int duration = 300}) {
5+
static Route<T> fadeThrough<T>(
6+
{required RouteSettings settings,
7+
required WidgetBuilder builder,
8+
int duration = 300}) {
79
return PageRouteBuilder<T>(
810
settings: settings,
911
transitionDuration: Duration(milliseconds: duration),
10-
pageBuilder: (context, animation, secondaryAnimation) => page(context),
12+
pageBuilder: (context, animation, secondaryAnimation) => builder(context),
1113
transitionsBuilder: (context, animation, secondaryAnimation, child) {
1214
return FadeScaleTransition(animation: animation, child: child);
1315
},
1416
);
1517
}
18+
19+
static Route<T> noAnimation<T>(
20+
{required RouteSettings settings, required WidgetBuilder builder}) {
21+
return PageRouteBuilder<T>(
22+
settings: settings,
23+
transitionDuration: Duration.zero,
24+
pageBuilder: (context, animation, secondaryAnimation) => builder(context),
25+
transitionsBuilder: (context, animation, secondaryAnimation, child) {
26+
return child;
27+
},
28+
);
29+
}
1630
}

0 commit comments

Comments
 (0)