| 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 | |
| 5 | import 'package:flutter/material.dart'; |
| 6 | |
| 7 | /// Flutter code sample for [PageTransitionsTheme]. |
| 8 | |
| 9 | void main() => runApp(const PageTransitionsThemeApp()); |
| 10 | |
| 11 | class PageTransitionsThemeApp extends StatelessWidget { |
| 12 | const PageTransitionsThemeApp({super.key}); |
| 13 | |
| 14 | @override |
| 15 | Widget build(BuildContext context) { |
| 16 | return MaterialApp( |
| 17 | theme: ThemeData( |
| 18 | pageTransitionsTheme: const PageTransitionsTheme( |
| 19 | builders: <TargetPlatform, PageTransitionsBuilder>{ |
| 20 | TargetPlatform.android: ZoomPageTransitionsBuilder(allowSnapshotting: false), |
| 21 | }, |
| 22 | ), |
| 23 | ), |
| 24 | home: const HomePage(), |
| 25 | ); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | class HomePage extends StatelessWidget { |
| 30 | const HomePage({super.key}); |
| 31 | |
| 32 | @override |
| 33 | Widget build(BuildContext context) { |
| 34 | return Scaffold( |
| 35 | backgroundColor: Colors.blueGrey, |
| 36 | body: Center( |
| 37 | child: ElevatedButton( |
| 38 | onPressed: () { |
| 39 | Navigator.of(context).push( |
| 40 | MaterialPageRoute<SecondPage>(builder: (BuildContext context) => const SecondPage()), |
| 41 | ); |
| 42 | }, |
| 43 | child: const Text('To SecondPage' ), |
| 44 | ), |
| 45 | ), |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | class SecondPage extends StatelessWidget { |
| 51 | const SecondPage({super.key}); |
| 52 | |
| 53 | @override |
| 54 | Widget build(BuildContext context) { |
| 55 | return Scaffold( |
| 56 | backgroundColor: Colors.purple[200], |
| 57 | body: Center( |
| 58 | child: ElevatedButton( |
| 59 | onPressed: () { |
| 60 | Navigator.of(context).pop(); |
| 61 | }, |
| 62 | child: const Text('Back to HomePage' ), |
| 63 | ), |
| 64 | ), |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | |