import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hero_animation/firstpage.dart';
import 'package:hero_animation/hero_animation.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
// counter didn't reset back to zero; the application is not restarted.
primarySwatch: Colors.blue,
),
home: new Material(
child: SafeArea(child: new MyHomePage(title: 'Flutter Demo Home Page')),
),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
Widget build(BuildContext context) {
List<BottomNavigationBarItem> items = CreateItems();
final CupertinoTabBar tabBar = new CupertinoTabBar(items: items);
// Scaffold
var scaffold = new CupertinoTabScaffold(
tabBar: tabBar,
tabBuilder: (ctx, index) {
switch (index) {
// VenuesNearBy
case 0:
{
return new CupertinoTabView(
builder: (ctx) {
return new HeroAnimation();
},
);
}
}
});
return scaffold;
}
List<BottomNavigationBarItem> CreateItems() {
var items = new List<BottomNavigationBarItem>();
items.add(new BottomNavigationBarItem(icon: new Icon(Icons.business), title: new Text("First")));
items.add(new BottomNavigationBarItem(icon: new Icon(Icons.business), title: new Text("Second")));
return items;
}
}
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
class PhotoHero extends StatelessWidget {
const PhotoHero({ Key key, this.photo, this.onTap, this.width }) : super(key: key);
final String photo; // = 'assets/superman.png';
final VoidCallback onTap;
final double width;
Widget build(BuildContext context) {
return SizedBox(
width: width,
child: Hero(
tag: photo,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
child: new Image.asset(
photo,
fit: BoxFit.contain,
),
),
),
),
);
}
}
class HeroAnimation extends StatelessWidget {
Widget build(BuildContext context) {
timeDilation = 5.0; // 1.0 means normal animation speed.
return Scaffold(
appBar: AppBar(
title: const Text('Basic Hero Animation'),
),
body: Center(
child: new PhotoHero(
photo: 'assets/superman.png',
width: 300.0,
onTap: () {
debugPrint("tapped");
Navigator.of(context).push(MaterialPageRoute<Null>(
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flippers Page'),
),
body: Container(
// The blue background emphasizes that it's a new route.
color: Colors.lightBlueAccent,
padding: const EdgeInsets.all(16.0),
alignment: Alignment.topLeft,
child: new PhotoHero(
photo: 'assets/superman.png',
width: 100.0,
onTap: () {
Navigator.of(context).pop();
},
),
),
);
}
));
},
),
),
);
}
}