text stringlengths 1 474 |
|---|
shapes intersect. At the beginning of the transition, |
the result of the intersection is a circular clip (ClipOval). |
During the transformation, the ClipOval scales from minRadius |
to maxRadius while the ClipRect maintains a constant size. |
At the end of the transition the intersection of the circular and |
rectangular clips yield a rectangle that’s the same size as the hero |
widget. In other words, at the end of the transition the image is no |
longer clipped.Create a new Flutter example and |
update it using the files from the |
radial_hero_animation GitHub directory.To run the example:<topic_end> |
<topic_start> |
Photo class |
The Photo class builds the widget tree that holds the image:Key information:<topic_end> |
<topic_start> |
RadialExpansion class |
The RadialExpansion widget, the core of the demo, builds the |
widget tree that clips the image during the transition. |
The clipped shape results from the intersection of a circular clip |
(that grows during flight), |
with a rectangular clip (that remains a constant size throughout).To do this, it builds the following widget tree:Here’s the code:Key information:The example defines the tweening interpolation using |
MaterialRectCenterArcTween. |
The default flight path for a hero animation |
interpolates the tweens using the corners of the heroes. |
This approach affects the hero’s aspect ratio during |
the radial transformation, so the new flight path uses |
MaterialRectCenterArcTween to interpolate the tweens using the |
center point of each hero.Here’s the code:The hero’s flight path still follows an arc, |
but the image’s aspect ratio remains constant. |
<topic_end> |
<topic_start>Animate a page route transition |
A design language, such as Material, defines standard behaviors when |
transitioning between routes (or screens). Sometimes, though, a custom |
transition between screens can make an app more unique. To help, |
PageRouteBuilder provides an Animation object. |
This Animation can be used with Tween and |
Curve objects to customize the transition animation. |
This recipe shows how to transition between |
routes by animating the new route into view from |
the bottom of the screen.To create a custom page route transition, this recipe uses the following steps:<topic_end> |
<topic_start> |
1. Set up a PageRouteBuilder |
To start, use a PageRouteBuilder to create a Route. |
PageRouteBuilder has two callbacks, one to build the content of the route |
(pageBuilder), and one to build the route’s transition (transitionsBuilder).info Note |
The child parameter in transitionsBuilder is the widget returned from |
pageBuilder. The pageBuilder function is only called the first time the |
route is built. The framework can avoid extra work because child stays the |
same throughout the transition.The following example creates two routes: a home route with a “Go!” button, and |
a second route titled “Page 2”. |
<code_start>import 'package:flutter/material.dart'; |
void main() { |
runApp( |
const MaterialApp( |
home: Page1(), |
), |
); |
} |
class Page1 extends StatelessWidget { |
const Page1({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
appBar: AppBar(), |
body: Center( |
child: ElevatedButton( |
onPressed: () { |
Navigator.of(context).push(_createRoute()); |
}, |
child: const Text('Go!'), |
), |
), |
); |
} |
} |
Route _createRoute() { |
return PageRouteBuilder( |
pageBuilder: (context, animation, secondaryAnimation) => const Page2(), |
transitionsBuilder: (context, animation, secondaryAnimation, child) { |
return child; |
}, |
); |
} |
class Page2 extends StatelessWidget { |
const Page2({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
appBar: AppBar(), |
body: const Center( |
child: Text('Page 2'), |
), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
2. Create a Tween |
To make the new page animate in from the bottom, it should animate from |
Offset(0,1) to Offset(0, 0) (usually defined using the Offset.zero |
constructor). In this case, the Offset is a 2D vector for the |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.