From c06755772dd45442493f3f93461cc69f39570c2e Mon Sep 17 00:00:00 2001 From: ny927 <32477115+ny927@users.noreply.github.com> Date: Wed, 9 Sep 2020 08:00:03 +0900 Subject: [PATCH] Add sample code to RelativePositionedTransition (#63940) --- .../flutter/lib/src/widgets/transitions.dart | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/packages/flutter/lib/src/widgets/transitions.dart b/packages/flutter/lib/src/widgets/transitions.dart index 0e86790ab1..2fb135c664 100644 --- a/packages/flutter/lib/src/widgets/transitions.dart +++ b/packages/flutter/lib/src/widgets/transitions.dart @@ -924,6 +924,61 @@ class PositionedTransition extends AnimatedWidget { /// animated by a [CurvedAnimation] set to [Curves.elasticInOut]: /// {@animation 300 378 https://flutter.github.io/assets-for-api-docs/assets/widgets/relative_positioned_transition.mp4} /// +/// {@tool dartpad --template=stateful_widget_material_ticker} +/// +/// The following code implements the [RelativePositionedTransition] as seen in the video +/// above: +/// +/// ```dart +/// AnimationController _controller; +/// +/// @override +/// void initState() { +/// super.initState(); +/// _controller = AnimationController( +/// duration: const Duration(seconds: 2), +/// vsync: this, +/// )..repeat(reverse: true); +/// } +/// +/// @override +/// void dispose() { +/// _controller.dispose(); +/// super.dispose(); +/// } +/// +/// @override +/// Widget build(BuildContext context) { +/// final double smallLogo = 100; +/// final double bigLogo = 200; +/// +/// return LayoutBuilder( +/// builder: (context, constraints) { +/// final Size biggest = constraints.biggest; +/// return Stack( +/// children: [ +/// RelativePositionedTransition( +/// size: biggest, +/// rect: RectTween( +/// begin: Rect.fromLTWH(0, 0, bigLogo, bigLogo), +/// end: Rect.fromLTWH(biggest.width - smallLogo, biggest.height - smallLogo, smallLogo, smallLogo), +/// ).animate(CurvedAnimation( +/// parent: _controller, +/// curve: Curves.elasticInOut, +/// )), +/// child: Padding( +/// padding: const EdgeInsets.all(8), +/// child: FlutterLogo() +/// ), +/// ), +/// ], +/// ); +/// }, +/// ); +/// } +/// ``` +/// {@end-tool} +/// /// See also: /// /// * [PositionedTransition], a widget that animates its child from a start