You can set the navigation theme in the root MaterialApp
. You can pass the navigation animation to each platform you are targeting as shown below.
MaterialApp(
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
),
);
But TargetPlatform
is not available for web, in fact it gets not the target platform but the OS the app is running on.
As a work around for this, you can use kIsWeb
Boolean from flutter foundation package, another thing you need a custom PageTransitionsBuilder
that has no animations.
custom PageTransitionsBuilder
class NoTransitionsBuilder extends PageTransitionsBuilder {
const NoTransitionsBuilder();
@override
Widget buildTransitions<T>(
PageRoute<T>? route,
BuildContext? context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget? child,
) {
// only return the child without warping it with animations
return child!;
}
}
Finally the pageTransitionsTheme
import 'package:flutter/foundation.dart' show kIsWeb;
pageTransitionsTheme: PageTransitionsTheme(
builders: kIsWeb
? {
// No animations for every OS if the app running on the web
for (final platform in TargetPlatform.values)
platform:const NoTransitionsBuilder(),
}
: const {
// handel other platforms you are targeting
},
),