Hero animations inside CupertinoTabBar - not working at all!

181 views
Skip to first unread message

Morten Overgaard

unread,
Aug 11, 2018, 2:13:32 PM8/11/18
to flutt...@googlegroups.com
Any one knows if Hero animations work when using CupertinoTabBar and  CupertinoTabScaffold ??

No Hero animaion occurs when running the below code ??

// code

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;
}
}

// HeroAnimation class

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();
},
),
),
);
}
));
},
),
),
);
}
}


;-)
/Morten

Mobil: 51 21 90 79

Jonathan White

unread,
Aug 13, 2018, 10:22:02 AM8/13/18
to Flutter Dev
Hmm. Does it work outside of the scaffold?

Morten Overgaard

unread,
Aug 14, 2018, 9:55:37 AM8/14/18
to thinkdigi...@gmail.com, flutt...@googlegroups.com
Works as expected when not using the CupertinoTabScaffold inside.
 
;-)
/Morten

Mobil: 51 21 90 79

On Mon, Aug 13, 2018 at 4:22 PM Jonathan White <thinkdigi...@gmail.com> wrote:
Hmm. Does it work outside of the scaffold?

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages