Last active
February 20, 2024 08:57
-
-
Save branflake2267/11b6d1462ec10cbdedccbe14c7ce06a1 to your computer and use it in GitHub Desktop.
Flutter - The Hero Animation - YouTube episode source code...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(new MyApp()); | |
} | |
/// Root MaterialApp | |
class MyApp extends StatelessWidget { | |
var _routes = <String, WidgetBuilder>{ | |
"/anotherPage": (BuildContext context) => | |
new AnotherPage(title: "Another Page"), | |
}; | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
title: 'Flutter Demo', | |
theme: new ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: new MyHomePage(title: 'Home Page'), | |
routes: _routes, | |
); | |
} | |
} | |
/// place: "/" | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => new _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
@override | |
Widget build(BuildContext context) { | |
// llama Image | |
var decoratedBox = new DecoratedBox( | |
decoration: new BoxDecoration( | |
image: new DecorationImage( | |
fit: BoxFit.fitWidth, | |
image: new AssetImage('images/llama.png'), | |
), | |
shape: BoxShape.circle, | |
) | |
); | |
// hero top left | |
var hero = new Hero( | |
tag: 'hero-tag-llama', | |
child: decoratedBox, | |
); | |
var _children = <Widget>[ | |
new Container( | |
height: 50.0, | |
width: 50.0, | |
child: hero, | |
), | |
]; | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text(widget.title), | |
), | |
body: new Column(children: _children), | |
floatingActionButton: new FloatingActionButton( | |
onPressed: _onPressed, | |
tooltip: 'Increment', | |
child: new Icon(Icons.done), | |
),); | |
} | |
void _onPressed() { | |
Navigator.of(context).pushNamed("/anotherPage"); | |
} | |
} | |
// place: "/anotherPage" | |
class AnotherPage extends StatefulWidget { | |
AnotherPage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_AnotherPageState createState() => new _AnotherPageState(); | |
} | |
class _AnotherPageState extends State<AnotherPage> { | |
@override | |
Widget build(BuildContext context) { | |
// llama Image | |
var decoratedBox = new DecoratedBox( | |
decoration: new BoxDecoration( | |
image: new DecorationImage( | |
fit: BoxFit.fitWidth, | |
image: new AssetImage('images/llama.png'), | |
), | |
shape: BoxShape.circle, | |
) | |
); | |
// hero center | |
var hero = new Hero( | |
tag: 'hero-tag-llama', | |
child: decoratedBox, | |
); | |
var center = new Center( | |
child: new Container( | |
height: 100.0, | |
width: 100.0, | |
child: hero, | |
),); | |
return new Scaffold( | |
appBar: new AppBar( | |
title: new Text(widget.title), | |
), | |
body: center, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Youtube episode: https://youtu.be/0oq6Ofh2WNg