diff --git a/lib/main.dart b/lib/main.dart index da6a074..50c20ae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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() { @@ -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, ); } @@ -52,25 +62,26 @@ class MyApp extends StatelessWidget { // Navigate using the page name, `Navigator.pushNamed(context, ListPage.name)`. Route buildPage( {required String path, Map 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(), + }; + }, + ); } } diff --git a/lib/main_advanced.dart b/lib/main_advanced.dart index 6ba3344..a12a448 100644 --- a/lib/main_advanced.dart +++ b/lib/main_advanced.dart @@ -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. diff --git a/lib/utils/no_animation_page_transitions_builder.dart b/lib/utils/no_animation_page_transitions_builder.dart new file mode 100644 index 0000000..f53a037 --- /dev/null +++ b/lib/utils/no_animation_page_transitions_builder.dart @@ -0,0 +1,14 @@ +import 'package:flutter/material.dart'; + +class NoAnimationPageTransitionsBuilder extends PageTransitionsBuilder { + @override + Widget buildTransitions( + PageRoute route, + BuildContext context, + Animation animation, + Animation secondaryAnimation, + Widget child, + ) { + return child; + } +}