From acd51a726e7c2eeb0e077890cd7b2f4f3bbc4931 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Mon, 16 Mar 2020 09:02:08 -0700 Subject: [PATCH] Make AnimatedSwitcher example into a dartpad example (#52547) --- .../lib/src/widgets/animated_switcher.dart | 81 +++++++++---------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/packages/flutter/lib/src/widgets/animated_switcher.dart b/packages/flutter/lib/src/widgets/animated_switcher.dart index a806e8eca7..9e7060f728 100644 --- a/packages/flutter/lib/src/widgets/animated_switcher.dart +++ b/packages/flutter/lib/src/widgets/animated_switcher.dart @@ -87,53 +87,48 @@ typedef AnimatedSwitcherLayoutBuilder = Widget Function(Widget currentChild, Lis /// progress indicator and the image will be fading out while a new progress /// indicator is fading in.) /// -/// {@tool snippet} +/// The type of transition can be changed from a cross-fade to a custom +/// transition by setting the [transitionBuilder]. +/// +/// {@tool dartpad --template=stateful_widget_material} +/// This sample shows a counter that animates the scale of a text widget +/// whenever the value changes. /// /// ```dart -/// class ClickCounter extends StatefulWidget { -/// const ClickCounter({Key key}) : super(key: key); +/// int _count = 0; /// -/// @override -/// _ClickCounterState createState() => _ClickCounterState(); -/// } -/// -/// class _ClickCounterState extends State { -/// int _count = 0; -/// -/// @override -/// Widget build(BuildContext context) { -/// return MaterialApp( -/// home: Material( -/// child: Column( -/// mainAxisAlignment: MainAxisAlignment.center, -/// children: [ -/// AnimatedSwitcher( -/// duration: const Duration(milliseconds: 500), -/// transitionBuilder: (Widget child, Animation animation) { -/// return ScaleTransition(child: child, scale: animation); -/// }, -/// child: Text( -/// '$_count', -/// // This key causes the AnimatedSwitcher to interpret this as a "new" -/// // child each time the count changes, so that it will begin its animation -/// // when the count changes. -/// key: ValueKey(_count), -/// style: Theme.of(context).textTheme.headline4, -/// ), -/// ), -/// RaisedButton( -/// child: const Text('Increment'), -/// onPressed: () { -/// setState(() { -/// _count += 1; -/// }); -/// }, -/// ), -/// ], +/// @override +/// Widget build(BuildContext context) { +/// return Container( +/// color: Colors.white, +/// child: Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: [ +/// AnimatedSwitcher( +/// duration: const Duration(milliseconds: 500), +/// transitionBuilder: (Widget child, Animation animation) { +/// return ScaleTransition(child: child, scale: animation); +/// }, +/// child: Text( +/// '$_count', +/// // This key causes the AnimatedSwitcher to interpret this as a "new" +/// // child each time the count changes, so that it will begin its animation +/// // when the count changes. +/// key: ValueKey(_count), +/// style: Theme.of(context).textTheme.headline4, +/// ), /// ), -/// ), -/// ); -/// } +/// RaisedButton( +/// child: const Text('Increment'), +/// onPressed: () { +/// setState(() { +/// _count += 1; +/// }); +/// }, +/// ), +/// ], +/// ), +/// ); /// } /// ``` /// {@end-tool}