gpt4 book ai didi

dart - Flutter:如何在英雄动画期间更改子元素的大小?

转载 作者:IT王子 更新时间:2023-10-29 07:06:45 25 4
gpt4 key购买 nike

我有一个 Hero,它有一个子元素,我想在英雄动画中更改大小(在本例中,我希望更改其纵横比)。

这是我的(简化的)构建方法:

Widget build(BuildContext build) {
final aspect = expanded ? 1.3 : 1.0;
return new Hero(
child: Column(
children: <Widget>[
new AspectRatio(
aspect: aspect,
child: // Stuff that creates a header
),
new Container(
child: // General descriptions
)
],
);
}

现在,纵横比在两个值之间跳跃。我的问题是,我能否将方面与英雄动画一起制作动画,并让它从 1.3 慢慢切换到 1.0 并返回?

有关完整示例(它还显示了英雄动画期间奇怪的溢出问题),请参阅此要点: https://gist.github.com/fuzzybinary/74196bccecc6dd070b35474c4c9223d7

最佳答案

因为我现在在家里,所以我现在无法试用您的代码。但是我有一个工作中的英雄动画示例。试试这个。

// main.dart class
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:flutter_test7/photo_hero.dart';
import 'package:flutter_test7/second_page.dart';

class HeroAnimation extends StatelessWidget {
Widget build(BuildContext context) {
timeDilation = 2.5; // 1.0 means normal animation speed.

return new Scaffold(
appBar: new AppBar(
title: const Text('Basic Hero Animation'),
),
body: new Center(
child: new PhotoHero(
photo: 'images/flippers-alpha.png',
width: 300.0,
onTap: () {
Navigator.of(context).pushNamed('/second_page');
},
),
),
);
}
}

void main() {
runApp(
new MaterialApp(
home: new HeroAnimation(),
routes: <String, WidgetBuilder>{
'/second_page': (context) => new SecondPage()
},
),
);
}

// photo_hero.dart class
import 'package:flutter/material.dart';

class PhotoHero extends StatelessWidget {
const PhotoHero({Key key, this.photo, this.onTap, this.width})
: super(key: key);

final String photo;
final VoidCallback onTap;
final double width;

Widget build(BuildContext context) {
return new SizedBox(
width: width,
child: new Hero(
tag: photo,
child: new Material(
color: Colors.transparent,
child: new InkWell(
onTap: onTap,
child: new Image.asset(
photo,
fit: BoxFit.contain,
),
),
),
),
);
}
}

// second_page.dart class
import 'package:flutter/material.dart';
import 'package:flutter_test7/photo_hero.dart';

class SecondPage extends StatefulWidget {
@override
_SecondPageState createState() => new _SecondPageState();
}

class _SecondPageState extends State<SecondPage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: const Text('Flippers Page'),
),
body: new Container(
color: Colors.lightBlueAccent,
padding: const EdgeInsets.all(16.0),
alignment: Alignment.topLeft,
child: new PhotoHero(
photo: 'images/flippers-alpha.png',
width: 100.0,
onTap: () {
Navigator.of(context).pop();
},
),
),
);
}
}

希望这对您有所帮助。

关于dart - Flutter:如何在英雄动画期间更改子元素的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50500994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com