mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Create an example for FadeForwardsTransitionsBuilder
This commit is contained in:
parent
146d3a5a4c
commit
2d31a90f2e
@ -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<TargetPlatform, PageTransitionsBuilder>.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: <Widget>[
|
||||
IconButton(icon: const Icon(Icons.search), onPressed: () {}),
|
||||
IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
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<Widget>.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<SecondPage>(
|
||||
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: <Widget>[
|
||||
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: <Widget>[
|
||||
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)
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -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));
|
||||
});
|
||||
|
||||
@ -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));
|
||||
});
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user