From 871b58986d6d401efb8dd66af67814bf37c42cd1 Mon Sep 17 00:00:00 2001 From: John Ryan Date: Tue, 9 Jul 2019 15:34:39 -0700 Subject: [PATCH] add sample code for AnimatedContainer (#35225) * add sample code for AnimatedContainer * use stateful_widget_scaffold snippet template * add sample explanation * add setState() to example assumptions for analyzer * update description * use snippet instead of sample * change sample to match assets-for-api-docs * remove constant * update AnimatedContainer sample description add indication the example is depicted by the video and animates when tapped * fix example formatting * make sample conform to 80 col limit * add "implemented below" to illustration description * formatting for readability --- .../lib/src/widgets/implicit_animations.dart | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 5ec919d1b8..8360a95c4d 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -22,6 +22,7 @@ import 'transitions.dart'; // @override // MyWidgetState createState() => MyWidgetState(); // } +// void setState(VoidCallback fn) { } /// An interpolation between two [BoxConstraints]. /// @@ -521,10 +522,43 @@ abstract class AnimatedWidgetBaseState exten /// /// {@youtube 560 315 https://www.youtube.com/watch?v=yI-8QHpGIP4} /// -/// Here's an illustration of what using this widget looks like, using a [curve] -/// of [Curves.fastOutSlowIn]. +/// Here's an illustration (implemented below) of what using this widget looks +/// like, using a [curve] of [Curves.fastOutSlowIn]. /// {@animation 250 266 https://flutter.github.io/assets-for-api-docs/assets/widgets/animated_container.mp4} /// +/// {@tool snippet --template=stateful_widget_scaffold} +/// +/// The following example (depicted above) transitions an AnimatedContainer +/// between two states. It adjusts the [height], [width], [color], and +/// [alignment] properties when tapped. +/// +/// ```dart +/// bool selected = false; +/// +/// @override +/// Widget build(BuildContext context) { +/// return GestureDetector( +/// onTap: () { +/// setState(() { +/// selected = !selected; +/// }); +/// }, +/// child: Center( +/// child: AnimatedContainer( +/// width: selected ? 200.0 : 100.0, +/// height: selected ? 100.0 : 200.0, +/// color: selected ? Colors.red : Colors.blue, +/// alignment: selected ? Alignment.center : AlignmentDirectional.topCenter, +/// duration: Duration(seconds: 2), +/// curve: Curves.fastOutSlowIn, +/// child: FlutterLogo(size: 75), +/// ), +/// ), +/// ); +/// } +/// ``` +/// {@end-tool} +/// /// See also: /// /// * [AnimatedPadding], which is a subset of this widget that only