Flutter 如何在Flitter中将英雄动画添加到我的ListView?
我有一个列表视图,它有如下所示的卡片。我正在尝试动画卡打开一个更大的尺寸时被按下 我已经为一张卡实现了这一点,但是我不明白如何为ListView实现这一点。在ListView元素上添加Hero标记时,出现以下错误:Flutter 如何在Flitter中将英雄动画添加到我的ListView?,flutter,user-interface,animation,dart,Flutter,User Interface,Animation,Dart,我有一个列表视图,它有如下所示的卡片。我正在尝试动画卡打开一个更大的尺寸时被按下 我已经为一张卡实现了这一点,但是我不明白如何为ListView实现这一点。在ListView元素上添加Hero标记时,出现以下错误: There are multiple heroes that share the same tag within a subtree. 这是最新的 这是动画的代码: 第一页: Widget build(BuildContext context) { return new
There are multiple heroes that share the same tag within a subtree.
这是最新的
这是动画的代码:
第一页:
Widget build(BuildContext context) {
return new Scaffold(
body: Hero(
tag: 'flutterLogo',
child: GestureDetector(
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => AnimatedPage())),
child: Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
height: 180,
width: 300,
color: Colors.blue,
),
),
)),
);
}
第二页:
Widget build(BuildContext context) {
return new Scaffold(
body: Stack(
children: <Widget>[
Hero(
tag: 'flutterLogo',
child: Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Card(
elevation: 4.0,
color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
height: 200,
width: 300,
child: Center(child: Text('Hello')),
),
),
),
),
],
),
);
}
下面是列表的内容:
我正试着打开同样的门
单击列表中的卡后,如动画中所示的第二页。英雄标记应该不同,因此在您的
SliverList
中将您的标记更改为:
tag: 'flutterLogo${index}',
然后将标记传递到第二个页面,如下所示(如果是StatefulWidget
):
然后,不要在第二页中使用简单的标记,而是使用如下内容:
tag: widget.heroTag,
这回答了你的问题吗?我看到了这一点,但我不明白如何在我的案例中实现@NileshRathod通过@NileshRathod传递到链接,您可以这样做,在
SliverList
中使用tag:'flatterlogo$index'
并修改SecondPage
将tag
作为参数,如PaymentPage('flatterlogo$index'))
并在SecondPage
class SecondPage extends StatefulWidget {
final String heroTag;
SecondPage({Key key, this.heroTag}) : super(key: key);
@override
_SecondPageState createState() => _SecondPageState();
}
tag: widget.heroTag,