text stringlengths 1 372 |
|---|
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 |
‘fractionaltranslation’ widget. |
setting the dy argument to 1 represents a vertical translation one |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.