微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

routes – 在Row抛出错误的相同颤振窗口小部件?

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

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 FloatingActionButton(
                    child: new Icon(Icons.add),onpressed: _increment),],)

这是我如何路由到我的文件

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

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

解决方法

尝试为每个FloatingActionButtons添加一个唯一的 heroTag,这样Flutter就不会将这两个按钮相互混淆,例如:

new Row(
        mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
          new FloatingActionButton(
              heroTag: "Decline",child: new Icon(Icons.remove),new Text(
            _count.toString(),style: new TextStyle(
                fontSize: 40.0,new FloatingActionButton(
              heroTag: "Increment",child: new Icon(Icons.add),

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐