diff --git a/examples/api/lib/material/page_transitions_theme/page_transitions_theme.3.dart b/examples/api/lib/material/page_transitions_theme/page_transitions_theme.3.dart new file mode 100644 index 00000000000..392b9a624e6 --- /dev/null +++ b/examples/api/lib/material/page_transitions_theme/page_transitions_theme.3.dart @@ -0,0 +1,145 @@ +// 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'; + +/// 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( + debugShowCheckedModeBanner: false, + theme: ThemeData( + pageTransitionsTheme: PageTransitionsTheme( + builders: Map.fromIterable( + TargetPlatform.values, value: (_) => const FadeForwardsPageTransitionsBuilder() + ), + ), + ), + home: const HomePage(), + ); + } +} + +class HomePage extends StatelessWidget { + const HomePage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + leading: IconButton(icon: const Icon(Icons.dehaze), onPressed: () {}), + actions: [ + IconButton(icon: const Icon(Icons.search), onPressed: () {}), + IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}), + ], + ), + body: Column( + children: [ + Text('Messages', style: Theme.of(context).textTheme.headlineLarge), + Expanded( + child: Padding( + padding: const EdgeInsets.all(20.0), + child: Card( + clipBehavior: Clip.antiAlias, + elevation: 0, + color: Theme.of(context).colorScheme.surfaceContainerLowest, + child: ListView( + children: List.generate(Colors.primaries.length, (int index) { + final Text kittenName = Text('Kitten $index'); + final CircleAvatar avatar = CircleAvatar(backgroundColor: Colors.primaries[index]); + final String message = index.isEven + ? 'Hello hooman! My name is Kitten $index' + : "What's up hooman! My name is Kitten $index"; + return ListTile( + leading: avatar, + title: kittenName, + subtitle: Text(message), + trailing: Text('$index seconds ago'), + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) + => SecondPage( + kittenName: kittenName, + avatar: avatar, + message: message, + ), + ), + ); + }, + ); + }), + ), + ), + ), + ), + ], + ) + ); + } +} + +class SecondPage extends StatelessWidget { + const SecondPage({ + super.key, + required this.kittenName, + required this.avatar, + required this.message, + }); + final Text kittenName; + final CircleAvatar avatar; + final String message; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + leading: const BackButton(), + title: kittenName, + centerTitle: false, + actions: [ + IconButton(icon: const Icon(Icons.search), onPressed: () {}), + IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}), + ], + ), + body: Padding( + padding: const EdgeInsets.all(20.0), + child: IntrinsicHeight( + child: Row( + children: [ + avatar, + ConstrainedBox( + constraints: const BoxConstraints(minHeight: 50), + child: Card( + elevation: 0.0, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(20), + topRight: Radius.circular(20), + bottomLeft: Radius.circular(5), + bottomRight: Radius.circular(20), + ) + ), + color: Theme.of(context).colorScheme.surfaceContainerLowest, + child: Center( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 15.0), + child: Text(message) + ), + ), + ), + ) + ], + ), + ), + ), + ); + } +} diff --git a/examples/api/lib/widgets/heroes/hero.1.dart b/examples/api/lib/widgets/heroes/hero.1.dart index 63d6931c38c..28e8795a991 100644 --- a/examples/api/lib/widgets/heroes/hero.1.dart +++ b/examples/api/lib/widgets/heroes/hero.1.dart @@ -19,7 +19,10 @@ class HeroApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - theme: ThemeData(useMaterial3: true), + theme: ThemeData( + platform: TargetPlatform.android + // pageTransitionsTheme: + ), home: const HeroExample(), ); } diff --git a/examples/api/test/widgets/heroes/hero.0_test.dart b/examples/api/test/widgets/heroes/hero.0_test.dart index 058436ddb09..fb93f0220d0 100644 --- a/examples/api/test/widgets/heroes/hero.0_test.dart +++ b/examples/api/test/widgets/heroes/hero.0_test.dart @@ -18,26 +18,26 @@ void main() { Size heroSize = tester.getSize(find.byType(Container)); - // Jump 25% into the transition (total length = 300ms) - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + // Jump 25% into the transition (total length = 800ms) + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize.width.roundToDouble(), 103.0); expect(heroSize.height.roundToDouble(), 60.0); // Jump to 50% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize.width.roundToDouble(), 189.0); expect(heroSize.height.roundToDouble(), 146.0); // Jump to 75% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize.width.roundToDouble(), 199.0); expect(heroSize.height.roundToDouble(), 190.0); // Jump to 100% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize, const Size(200.0, 200.0)); @@ -45,26 +45,26 @@ void main() { await tester.tap(find.byIcon(Icons.arrow_back)); await tester.pump(); - // Jump 25% into the transition (total length = 300ms) - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + // Jump 25% into the transition (total length = 800ms) + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize.width.roundToDouble(), 199.0); expect(heroSize.height.roundToDouble(), 190.0); // Jump to 50% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize.width.roundToDouble(), 189.0); expect(heroSize.height.roundToDouble(), 146.0); // Jump to 75% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize.width.roundToDouble(), 103.0); expect(heroSize.height.roundToDouble(), 60.0); // Jump to 100% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container)); expect(heroSize, const Size(50.0, 50.0)); }); diff --git a/examples/api/test/widgets/heroes/hero.1_test.dart b/examples/api/test/widgets/heroes/hero.1_test.dart index 1fab344d829..d3d45a14fd3 100644 --- a/examples/api/test/widgets/heroes/hero.1_test.dart +++ b/examples/api/test/widgets/heroes/hero.1_test.dart @@ -19,26 +19,26 @@ void main() { Size heroSize = tester.getSize(find.byType(Container).first); expect(heroSize, const Size(50.0, 50.0)); - // Jump 25% into the transition (total length = 300ms) - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + // Jump 25% into the transition (total length = 800ms) + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 170.0); expect(heroSize.height.roundToDouble(), 73.0); // Jump to 50% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 371.0); expect(heroSize.height.roundToDouble(), 273.0); // Jump to 75% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 398.0); expect(heroSize.height.roundToDouble(), 376.0); // Jump to 100% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize, const Size(400.0, 400.0)); @@ -46,26 +46,26 @@ void main() { await tester.tap(find.byIcon(Icons.arrow_back)); await tester.pump(); - // Jump 25% into the transition (total length = 300ms) - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + // Jump 25% into the transition (total length = 800ms) + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 398.0); expect(heroSize.height.roundToDouble(), 376.0); // Jump to 50% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 371.0); expect(heroSize.height.roundToDouble(), 273.0); // Jump to 75% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 170.0); expect(heroSize.height.roundToDouble(), 73.0); // Jump to 100% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize, const Size(50.0, 50.0)); }); @@ -82,26 +82,26 @@ void main() { Size heroSize = tester.getSize(find.byType(Container).last); expect(heroSize, const Size(50.0, 50.0)); - // Jump 25% into the transition (total length = 300ms) - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + // Jump 25% into the transition (total length = 800ms) + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize.width.roundToDouble(), 133.0); expect(heroSize.height.roundToDouble(), 133.0); // Jump to 50% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize.width.roundToDouble(), 321.0); expect(heroSize.height.roundToDouble(), 321.0); // Jump to 75% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).first); expect(heroSize.width.roundToDouble(), 398.0); expect(heroSize.height.roundToDouble(), 376.0); // Jump to 100% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize, const Size(400.0, 400.0)); @@ -109,26 +109,26 @@ void main() { await tester.tap(find.byIcon(Icons.arrow_back)); await tester.pump(); - // Jump 25% into the transition (total length = 300ms) - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + // Jump 25% into the transition (total length = 800ms) + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize.width.roundToDouble(), 386.0); expect(heroSize.height.roundToDouble(), 386.0); // Jump to 50% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize.width.roundToDouble(), 321.0); expect(heroSize.height.roundToDouble(), 321.0); // Jump to 75% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize.width.roundToDouble(), 133.0); expect(heroSize.height.roundToDouble(), 133.0); // Jump to 100% into the transition. - await tester.pump(const Duration(milliseconds: 75)); // 25% of 300ms + await tester.pump(const Duration(milliseconds: 200)); // 25% of 800ms heroSize = tester.getSize(find.byType(Container).last); expect(heroSize, const Size(50.0, 50.0)); }); diff --git a/examples/api/test/widgets/transitions/fade_transition.0_test.dart b/examples/api/test/widgets/transitions/fade_transition.0_test.dart index 1bed187a93f..e0a88fca9ff 100644 --- a/examples/api/test/widgets/transitions/fade_transition.0_test.dart +++ b/examples/api/test/widgets/transitions/fade_transition.0_test.dart @@ -18,7 +18,10 @@ void main() { expect( find.ancestor( of: find.byType(FlutterLogo), - matching: find.byType(FadeTransition), + matching: find.descendant( + of: find.byType(ColoredBox), + matching: find.byType(FadeTransition) + ), ), findsOneWidget, ); @@ -31,7 +34,10 @@ void main() { final Finder fadeTransitionFinder = find.ancestor( of: find.byType(FlutterLogo), - matching: find.byType(FadeTransition), + matching: find.descendant( + of: find.byType(ColoredBox), + matching: find.byType(FadeTransition) + ), ); const double beginOpacity = 0.0; diff --git a/packages/flutter/lib/src/material/page_transitions_theme.dart b/packages/flutter/lib/src/material/page_transitions_theme.dart index 028f5b325aa..dcd61b32f33 100644 --- a/packages/flutter/lib/src/material/page_transitions_theme.dart +++ b/packages/flutter/lib/src/material/page_transitions_theme.dart @@ -724,6 +724,12 @@ class OpenUpwardsPageTransitionsBuilder extends PageTransitionsBuilder { /// transition animation that looks like the default page transition /// used on Android U. /// +/// {@tool dartpad} +/// This example shows the default page transition on Android. +/// +/// ** See code in examples/api/lib/material/page_transitions_theme/page_transitions_theme.3.dart ** +/// {@end-tool} +/// /// See also: /// /// * [FadeUpwardsPageTransitionsBuilder], which defines a page transition @@ -1030,7 +1036,7 @@ class CupertinoPageTransitionsBuilder extends PageTransitionsBuilder { /// and delegates to [buildTransitions]. /// /// If a builder with a matching platform is not found, then the -/// [ZoomPageTransitionsBuilder] is used. +/// [FadeForwardsPageTransitionsBuilder] is used. /// /// {@tool dartpad} /// This example shows a [MaterialApp] that defines a custom [PageTransitionsTheme]. @@ -1048,6 +1054,8 @@ class CupertinoPageTransitionsBuilder extends PageTransitionsBuilder { /// 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. @immutable