1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [PageTransitionsTheme].
8
9void main() => runApp(const PageTransitionsThemeApp());
10
11class PageTransitionsThemeApp extends StatelessWidget {
12 const PageTransitionsThemeApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return MaterialApp(
17 theme: ThemeData(
18 // Defines the page transition animations used by MaterialPageRoute
19 // for different target platforms.
20 // Non-specified target platforms will default to
21 // ZoomPageTransitionsBuilder().
22 pageTransitionsTheme: const PageTransitionsTheme(
23 builders: <TargetPlatform, PageTransitionsBuilder>{
24 TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
25 TargetPlatform.linux: OpenUpwardsPageTransitionsBuilder(),
26 TargetPlatform.macOS: FadeUpwardsPageTransitionsBuilder(),
27 },
28 ),
29 ),
30 home: const HomePage(),
31 );
32 }
33}
34
35class HomePage extends StatelessWidget {
36 const HomePage({super.key});
37
38 @override
39 Widget build(BuildContext context) {
40 return Scaffold(
41 backgroundColor: Colors.blueGrey,
42 body: Center(
43 child: ElevatedButton(
44 onPressed: () {
45 Navigator.of(context).push(
46 MaterialPageRoute<SecondPage>(builder: (BuildContext context) => const SecondPage()),
47 );
48 },
49 child: const Text('To SecondPage'),
50 ),
51 ),
52 );
53 }
54}
55
56class SecondPage extends StatelessWidget {
57 const SecondPage({super.key});
58
59 @override
60 Widget build(BuildContext context) {
61 return Scaffold(
62 backgroundColor: Colors.purple[200],
63 body: Center(
64 child: ElevatedButton(
65 onPressed: () {
66 Navigator.of(context).pop();
67 },
68 child: const Text('Back to HomePage'),
69 ),
70 ),
71 );
72 }
73}
74