Skip to content

Commit

Permalink
Create NoAnimationPageTransitionsBuilder
Browse files Browse the repository at this point in the history
- Replace Route builder with NoAnimationPageTransitionsBuilder.
  • Loading branch information
rayliverified committed Sep 5, 2024
1 parent 4079e0d commit b887619
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
53 changes: 32 additions & 21 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
// ignore: depend_on_referenced_packages
import 'package:flutter_web_plugins/url_strategy.dart';
import 'package:minimal/pages/pages.dart';
import 'package:minimal/routes.dart';
import 'package:minimal/utils/no_animation_page_transitions_builder.dart';
import 'package:responsive_framework/responsive_framework.dart';

void main() {
Expand Down Expand Up @@ -44,6 +44,16 @@ class MyApp extends StatelessWidget {
final Uri uri = Uri.parse(settings.name ?? '/');
return buildPage(path: uri.path, queryParams: uri.queryParameters);
},
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.fuchsia: NoAnimationPageTransitionsBuilder(),
TargetPlatform.linux: NoAnimationPageTransitionsBuilder(),
TargetPlatform.macOS: NoAnimationPageTransitionsBuilder(),
TargetPlatform.windows: NoAnimationPageTransitionsBuilder(),
},
),
),
debugShowCheckedModeBanner: false,
);
}
Expand All @@ -52,25 +62,26 @@ class MyApp extends StatelessWidget {
// Navigate using the page name, `Navigator.pushNamed(context, ListPage.name)`.
Route<dynamic> buildPage(
{required String path, Map<String, String> queryParams = const {}}) {
return Routes.noAnimation(
settings: RouteSettings(
name: (path.startsWith('/') == false) ? '/$path' : path),
builder: (context) {
String pathName =
path != '/' && path.startsWith('/') ? path.substring(1) : path;
return switch (pathName) {
'/' || ListPage.name => const ListPage(),
PostPage.name =>
// Breakpoints can be nested.
// Here's an example of custom "per-page" breakpoints.
const ResponsiveBreakpoints(breakpoints: [
Breakpoint(start: 0, end: 480, name: MOBILE),
Breakpoint(start: 481, end: 1200, name: TABLET),
Breakpoint(start: 1201, end: double.infinity, name: DESKTOP),
], child: PostPage()),
TypographyPage.name => const TypographyPage(),
_ => const SizedBox.shrink(),
};
});
return PageRouteBuilder(
settings: RouteSettings(
name: (path.startsWith('/') == false) ? '/$path' : path),
pageBuilder: (context, animation, secondaryAnimation) {
String pathName =
path != '/' && path.startsWith('/') ? path.substring(1) : path;
return switch (pathName) {
'/' || ListPage.name => const ListPage(),
PostPage.name =>
// Breakpoints can be nested.
// Here's an example of custom "per-page" breakpoints.
const ResponsiveBreakpoints(breakpoints: [
Breakpoint(start: 0, end: 480, name: MOBILE),
Breakpoint(start: 481, end: 1200, name: TABLET),
Breakpoint(start: 1201, end: double.infinity, name: DESKTOP),
], child: PostPage()),
TypographyPage.name => const TypographyPage(),
_ => const SizedBox.shrink(),
};
},
);
}
}
2 changes: 1 addition & 1 deletion lib/main_advanced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MyApp extends StatelessWidget {
// behavior for a page.
onGenerateRoute: (RouteSettings settings) {
// A custom `fadeThrough` route transition animation.
return Routes.fadeThrough(
return Routes.noAnimation(
settings: settings,
builder: (context) {
// Wrap widgets with another widget based on the route.
Expand Down
14 changes: 14 additions & 0 deletions lib/utils/no_animation_page_transitions_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';

class NoAnimationPageTransitionsBuilder extends PageTransitionsBuilder {
@override
Widget buildTransitions<T>(
PageRoute<T> route,
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) {
return child;
}
}

0 comments on commit b887619

Please sign in to comment.