上周我一直在学习颤动动画。在我的旧项目中实现动画时,我发现英雄动画无法正常工作的问题,我已经在Google上搜索了好几个小时,没有找到合适的解决方案。所以我有4个文件(2个父母和2个孩子),我认为错误是导航器从一个屏幕(文件)传递到另一个屏幕,而英雄动画在自定义窗口小部件中,而子窗口却在子窗口中?他们父母的文件。抱歉,这个令人困惑的解释会让我知道,如果您理解它,代码将有望澄清这一点。
//gridviewMemories.dart
List.generate(memoriesArray.length, (int index) {
print('made it till grid');
return Padding(
padding: EdgeInsets.symmetric(horizontal: 1.1, vertical: 1.1),
child: MemoriesChild(
id: memoriesArray[index]['id'],
snap: memoriesArray[index]['snap'],
date: memoriesArray[index]['date'],
index: index,
));
})
//gridviewMemoriesChild.dart
videoOrImage(BuildContext context) {
if (widget.snap.contains('mp4?')) {
return FutureBuilder(
future: hasInitialized,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done ||
snapshot.connectionState == ConnectionState.waiting) {
return VideoPlayer(_controller);
} else {
return Container(color: Colors.grey[300],);
}
});
} else {
return Container(
alignment: Alignment.center,
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
color: Colors.grey[300],
image: DecorationImage(
image: NetworkImage(
widget.snap,
),
fit: BoxFit.cover,
)),
);
}
}
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ShowDetails(
index: widget.index,
))); },
child: Hero(tag: 'index-${widget.index}', child: Container(child: videoOrImage(context))));
//showDetails.dart
MemorySnapChild(
theFile: memoriesArray[index]['snap'],
ctrl: _controller,
index: widget.index,
)
//showDetailsChild.dart
videoOrImage(BuildContext context) {
if (widget.theFile.contains('mp4?')) {
return FutureBuilder(
future: hasInitialized,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done ||
snapshot.connectionState == ConnectionState.waiting) {
return VideoPlayer(_controller);
} else {
return Container();
}
});
} else {
return Container(
alignment: Alignment.center,
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
color: Colors.grey[300],
image: DecorationImage(
image: NetworkImage(
widget.theFile,
),
fit: BoxFit.cover,
)),
);
}
}
Widget build(BuildContext context) {
return Stack(children: [
Hero(tag: 'index-${widget.index}', child: Container(child: videoOrImage(context))),
]);
答案 0 :(得分:0)
嘿,我找到了解决问题的方法。由于英雄小部件动画在我的代码中存在问题,因此我添加了animations package并使用容器变换来模拟英雄动画。希望这个答案可以帮助其他人<3