import ‘package:flutter/cupertino.dart’;
import ‘package:flutter/material.dart’;
import ‘package:flutter/scheduler.dart’ show timeDilation;
class PhotoHero extends StatelessWidget {
final String photo;
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: Image.network(
photo,
fit: BoxFit.contain,
),
),
),
),
);
}
}
class HeroAnimation extends StatelessWidget {
@override
Widget build(BuildContext context) {
timeDilation = 10.0; //正常动画速度
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text(“你好”),
),
body: Center(
child: PhotoHero(
photo:
“https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1595506145397&di=d2329b0a785fac8fc7f620b4fa5801e6&imgtype=0&src=http%3A%2F%2Fpic2.zhimg.com%2Fv2-bc0c14278ec0e2c604f9307a5323815b_1200x500.jpg”,
width: 300.0,
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => MaterialApp(home: NewAnimation(),)));
},
),
),
),
);
}
}
class NewAnimation extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(“Hello”),
),
body: Container(
color: Colors.lightBlueAccent,
padding: EdgeInsets.all(16.0),
alignment: Alignment.topLeft,
child: PhotoHero(
photo:
“https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1595506145397&di=d2329b0a785fac8fc7f620b4fa5801e6&imgtype=0&src=http%3A%2F%2Fpic2.zhimg.com%2Fv2-bc0c14278ec0e2c604f9307a5323815b_1200x500.jpg”,
width: 300.0,
onTap: () {
Navigator.of(context).pop();
}),
),
);
}
}
解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。
了解课程