5
votes

I'm producing 2 FloatingActionButtons within a Row. I'm getting the following error when routing to its file...

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'".

Here is my code...

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),
              ],
            )

This is how I'm routing to my file...

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

When I comment out the first FloatingActionButton it works fine. It only errors out when they're both used. My Row is also a child of a Column widget if that matters.

2

2 Answers

11
votes

Try adding a unique heroTag for each of the FloatingActionButtons, so that Flutter does not confuse the two button with each other, something like:

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),
        ],
      ),
0
votes

We cannot use more than one floating action button on the same page so there are two possibilities.

  1. Don't use more than one floating action button (Flutter is awesome so there are other ways to get the same result)
  2. Don't leave heroTag null.