PageTransitionsTheme class
Defines the page transition animations used by MaterialPageRoute for different TargetPlatforms.
The MaterialPageRoute.buildTransitions method looks up the
current PageTransitionsTheme with Theme.of(context).pageTransitionsTheme
and delegates to buildTransitions.
If a builder with a matching platform is not found, then the ZoomPageTransitionsBuilder is used.
This example shows a MaterialApp that defines a custom PageTransitionsTheme.
To see it in action, copy and run this code snippet on DartPad.
import 'package:cupertino_ui/cupertino_ui.dart';
import 'package:material_ui/material_ui.dart';
/// Flutter code sample for [PageTransitionsTheme].
void main() => runApp(const PageTransitionsThemeApp());
class PageTransitionsThemeApp extends StatelessWidget {
const PageTransitionsThemeApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
// Defines the page transition animations used by MaterialPageRoute
// for different target platforms.
// Non-specified target platforms will default to
// ZoomPageTransitionsBuilder().
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
.iOS: CupertinoPageTransitionsBuilder(),
.linux: OpenUpwardsPageTransitionsBuilder(),
.macOS: FadeUpwardsPageTransitionsBuilder(),
},
),
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey,
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<SecondPage>(
builder: (BuildContext context) => const SecondPage(),
),
);
},
child: const Text('To SecondPage'),
),
),
);
}
}
class SecondPage extends StatelessWidget {
const SecondPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.purple[200],
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Back to HomePage'),
),
),
);
}
}
See also:
- ThemeData.pageTransitionsTheme, which defines the default page transitions for the overall theme.
- FadeUpwardsPageTransitionsBuilder, which defines a page transition that's similar to the one provided by Android O.
- OpenUpwardsPageTransitionsBuilder, which defines a page transition that's similar to the one provided by Android P.
- ZoomPageTransitionsBuilder, which defines the default page transition that's similar to the one provided by Android Q.
- FadeForwardsPageTransitionsBuilder, which defines the default page transition that's similar to the one provided by Android U.
CupertinoPageTransitionsBuilder, which defines a horizontal page transition that matches native iOS page transitions.
- Mixed-in types
- Annotations
Constructors
-
PageTransitionsTheme({Map<
TargetPlatform, PageTransitionsBuilder> builders = _defaultBuilders}) -
Constructs an object that selects a transition based on the platform.
const
Properties
-
builders
→ Map<
TargetPlatform, PageTransitionsBuilder> -
The PageTransitionsBuilders supported by this theme.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
buildTransitions<
T> (PageRoute< T> route, BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) → Widget - Delegates to the builder for the current ThemeData.platform. If a builder for the current platform is not found, then the ZoomPageTransitionsBuilder is used.
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
delegatedTransition(
TargetPlatform platform) → DelegatedTransitionBuilder? - Provides the delegate transition for the target platform.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override