forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup PageTransitionsTheme documentation and add one example (#121701)
Cleanup PageTransitionsTheme documentation and add one example
- Loading branch information
Showing
3 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
examples/api/lib/material/page_transitions_theme/page_transitions_theme.0.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// Flutter code sample for [PageTransitionsTheme]. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
void main() => runApp(const PageTransitionsThemeApp()); | ||
|
||
class PageTransitionsThemeApp extends StatelessWidget { | ||
const PageTransitionsThemeApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData( | ||
useMaterial3: true, | ||
// 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>{ | ||
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), | ||
TargetPlatform.linux: OpenUpwardsPageTransitionsBuilder(), | ||
TargetPlatform.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'), | ||
), | ||
), | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
examples/api/test/material/page_transitions_theme/page_transitions_theme.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_api_samples/material/page_transitions_theme/page_transitions_theme.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('MaterialApp defines a custom PageTransitionsTheme', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.PageTransitionsThemeApp(), | ||
); | ||
|
||
final Finder homePage = find.byType(example.HomePage); | ||
expect(homePage, findsOneWidget); | ||
|
||
final PageTransitionsTheme theme = Theme.of(tester.element(homePage)).pageTransitionsTheme; | ||
expect(theme.builders, isNotNull); | ||
|
||
// Check defined page transitions builder for each platform. | ||
for (final TargetPlatform platform in TargetPlatform.values) { | ||
switch (platform) { | ||
case TargetPlatform.iOS: | ||
expect(theme.builders[platform], isA<CupertinoPageTransitionsBuilder>()); | ||
break; | ||
case TargetPlatform.linux: | ||
expect(theme.builders[platform], isA<OpenUpwardsPageTransitionsBuilder>()); | ||
break; | ||
case TargetPlatform.macOS: | ||
expect(theme.builders[platform], isA<FadeUpwardsPageTransitionsBuilder>()); | ||
break; | ||
case TargetPlatform.android: | ||
case TargetPlatform.fuchsia: | ||
case TargetPlatform.windows: | ||
expect(theme.builders[platform], isNull); | ||
break; | ||
} | ||
} | ||
|
||
// Can navigate to the second page. | ||
expect(find.text('To SecondPage'), findsOneWidget); | ||
await tester.tap(find.text('To SecondPage')); | ||
await tester.pumpAndSettle(); | ||
|
||
// Can navigate back to the home page. | ||
expect(find.text('Back to HomePage'), findsOneWidget); | ||
await tester.tap(find.text('Back to HomePage')); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('To SecondPage'), findsOneWidget); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters