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

时间:2017-10-01 05:39:08

标签: routes widget row flutter

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

  

在调度程序回调期间抛出以下断言:       有多个英雄在子树中共享相同的标记。       在每个要为其设置动画英雄的子树内(通常是PageRoute子树),每个英雄       必须具有唯一的非null标记。       在这种情况下,多个英雄的标签为“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小部件的子项。

2 个答案:

答案 0 :(得分:8)

尝试为每个FloatingActionButton添加唯一的heroTag,以便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),
        ],
      ),

答案 1 :(得分:0)

我们不能在同一页面上使用多个浮动动作按钮,因此有两种可能性。

  1. 不要使用多个浮动操作按钮(Flutter非常棒 因此还有其他方法可以获得相同的结果)
  2. 不要将heroTag留空。