Skip to content

Instantly share code, notes, and snippets.

@branflake2267
Last active February 20, 2024 08:57
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save branflake2267/11b6d1462ec10cbdedccbe14c7ce06a1 to your computer and use it in GitHub Desktop.
Save branflake2267/11b6d1462ec10cbdedccbe14c7ce06a1 to your computer and use it in GitHub Desktop.
Flutter - The Hero Animation - YouTube episode source code...
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,
);
}
}
@branflake2267
Copy link
Author

branflake2267 commented Apr 30, 2017

The Youtube episode: https://youtu.be/0oq6Ofh2WNg

screen shot 2017-05-01 at 7 42 42 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment