Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identical Flutter Widgets in Row throwing error?

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.

like image 235
Charles Jr Avatar asked Oct 01 '17 05:10

Charles Jr


1 Answers

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),
        ],
      ),
like image 188
Shady Aziza Avatar answered Jan 04 '23 10:01

Shady Aziza