【发布时间】:2020-10-28 20:19:18
【问题描述】:
我有一个 ListView,其中包含如下所示的卡片。我正在尝试使卡片在被按下时以更大的尺寸打开。
我已经为一张卡片实现了这一点,但是我不明白如何为 ListView 做到这一点。在 ListView 元素上添加 Hero 标签后,我收到以下错误:
There are multiple heroes that share the same tag within a subtree.
这是animation。
这是动画的代码:
第一页:
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')),
),
),
),
),
],
),
);
}
这是我的 ListView 的代码:
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Hero(
tag: 'flutterLogo',
child: Padding(
padding: const EdgeInsets.only(top: 10.0, bottom: 10),
child: GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => PaymentPage()));
},
child: Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
child: Container(
height: 180,
width: 150,
),
),
),
),
);
},
childCount: 4,
),
),
我正在尝试打开相同的 第二页如动画所示,点击列表中的卡片后。
【问题讨论】:
-
我看到了这个但是我不明白如何在我的情况下实现这个@NileshRathod
-
引用@NileshRathod 的链接,您可以这样做,在
SliverList中使用tag: 'flutterLogo$index'并修改SecondPage以将tag作为参数,如PaymentPage('flutterLogo$index')和在SecondPage上的Hero小部件中使用它
标签: flutter user-interface animation dart