gpt4 book ai didi

routes - 相同的 Flutter Widgets in Row 抛出错误?

转载 作者:IT老高 更新时间:2023-10-28 12:37:13 24 4
gpt4 key购买 nike

我在一行中生成 2 个 FloatingActionButton。路由到其文件时出现以下错误...

The following assertion was thrown during a scheduler callback: There are multiple heroes that share the same tag within a subtree. Within each subtree for which heroes are to be animated (typically a PageRoute subtree), each Hero must have a unique non-null tag. In this case, multiple heroes had the tag "Instance of 'Object'".

这是我的代码...

new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FloatingActionButton(
child: new Icon(Icons.remove), onPressed: _decline),
new Padding(padding: new EdgeInsets.all(10.0)),
new Text(
_count.toString(),
style: new TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
new Padding(padding: new EdgeInsets.all(10.0)),
new FloatingActionButton(
child: new Icon(Icons.add), onPressed: _increment),
],
)

这就是我路由到我的文件的方式...

Navigator.push(context, new MaterialPageRoute(builder: (_) => new Video.VideoPage()));

当我注释掉第一个 FloatingActionButton 时,它工作正常。只有当它们都被使用时才会出错。如果这很重要,我的 Row 也是 Column 小部件的子级。

最佳答案

尝试添加唯一的 heroTag对于每个 FloatingActionButton,这样 Flutter 就不会混淆这两个按钮,例如:

new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FloatingActionButton(
heroTag: "Decline",
child: new Icon(Icons.remove), onPressed: _decline),
new Padding(padding: new EdgeInsets.all(10.0)),
new Text(
_count.toString(),
style: new TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
new Padding(padding: new EdgeInsets.all(10.0)),
new FloatingActionButton(
heroTag: "Increment",
child: new Icon(Icons.add), onPressed: _increment),
],
),

关于routes - 相同的 Flutter Widgets in Row 抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46509553/

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