From fd5668bb1d19c163cc63bc75a722681125bb8c87 Mon Sep 17 00:00:00 2001 From: Abhishek Ghaskata Date: Fri, 5 Feb 2021 00:06:03 +0530 Subject: [PATCH] Adding hero example (#74415) --- packages/flutter/lib/src/widgets/heroes.dart | 64 ++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index 2b7ec7dd82..c40ddbeaaa 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -101,6 +101,70 @@ enum HeroFlightDirection { /// /// {@youtube 560 315 https://www.youtube.com/watch?v=Be9UH1kXFDw} /// +/// {@tool dartpad --template=stateless_widget_material} +/// This sample shows a [Hero] used within a [ListTile]. +/// +/// Tapping on the Hero-wrapped rectangle triggers a hero +/// animation as a new [MaterialPageRoute] is pushed. Both the size +/// and location of the rectangle animates. +/// +/// Both widgets use the same [Hero.tag]. +/// +/// The Hero widget uses the matching tags to identify and execute this +/// animation. +/// +/// ```dart +/// Widget build(BuildContext context) { +/// return Column( +/// crossAxisAlignment: CrossAxisAlignment.start, +/// children: [ +/// SizedBox( +/// height: 20.0, +/// ), +/// ListTile( +/// leading: Hero( +/// tag: 'hero-rectangle', +/// child: _blueRectangle(Size(50,50)), +/// ), +/// onTap: () => _gotoDetailsPage(context), +/// title: Text('Tap on the icon to view hero animation transition.'), +/// ), +/// ], +/// ); +/// } +/// +/// Widget _blueRectangle(Size size) { +/// return Container( +/// width: size.width, +/// height: size.height, +/// color: Colors.blue, +/// ); +/// } +/// +/// void _gotoDetailsPage(BuildContext context) { +/// Navigator.of(context).push(MaterialPageRoute( +/// builder: (BuildContext context) => Scaffold( +/// appBar: AppBar( +/// title: Text('second Page'), +/// ), +/// body: Center( +/// child: Column( +/// mainAxisAlignment: MainAxisAlignment.center, +/// children: [ +/// Hero( +/// tag: 'hero-rectangle', +/// child: _blueRectangle(Size(200,200)), +/// ), +/// ], +/// ), +/// ), +/// ), +/// )); +/// } +/// +/// ``` +/// {@end-tool} +/// /// ## Discussion /// /// Heroes and the [Navigator]'s [Overlay] [Stack] must be axis-aligned for