0
votes
import 'package:flutter/material.dart';
import 'package:ui_mvc/Rings.dart';


class Diamonds extends StatefulWidget {
  @override
  _DiamondsState createState() => _DiamondsState();
}

class _DiamondsState extends State<Diamonds> {

  var dataList= [
    {
     "name": "A1",
      "image":"assets/1.jpg" ,
      "location": "Delhi",
    },
    {
      "name": "A2",
      "image": "assets/2.jpg" ,
      "location": "Delhi",
    },
    {
      "name": "A3",
      "image": "assets/3.jpg" ,
      "location": "Delhi",
    },
    {
      "name": "A4",
      "image": "assets/4.jpg" ,
      "location": "Delhi",
    },
    {
      "name": "A5",
      "image": "assets/5.jpg" ,
      "location": "Delhi",
    },

  ];
  @override
  Widget build(BuildContext context) {
    return GridView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: dataList.length,
        gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 1),
        itemBuilder: (BuildContext context,int index){
          return SingleProd(
            prodName: dataList[index]['name'],
            prodImage: dataList[index]['image'],
            prodLocation: dataList[index]['location'],
          );
        });
  }
}

class SingleProd extends StatelessWidget {
  final prodName;
  final prodImage;
  final prodLocation;

  SingleProd({
   this.prodName,
   this.prodImage,
   this.prodLocation,
});

  @override
  Widget build(BuildContext context) {
    return Card(
      child: Hero(
          tag: prodName,
          child: Material(
            child: InkWell(
              onTap: ()=>
                Navigator.of(context).push(
                  new MaterialPageRoute(builder: (context)=> new Rings())
                ),
              child: GridTile(
                footer: Container(
                  color: Colors.white,
                  child: ListTile(
                    title: Text(
                      prodName,
                      textAlign: TextAlign.left,
                    ),
                    subtitle: Text(
                      prodLocation,
                      textAlign: TextAlign.left,
                    ),
                  ),
                ),
                child: Image.asset(
                    prodImage,
                    fit: BoxFit.fitHeight)
              ),
            ),
          )
      ),
    );
  }
}

So I'm trying to display a horizontal list with 5 tiles. I want each tile to redirect to the same page (for the time being) that's why I call Rings() which is defined in another page. And upon tapping one of the tiles the screen goes black. But it just keeps on showing me this error: 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 (i.e. a PageRoute subtree), each Hero must have a unique non-null tag. In this case, multiple heroes had the following tag: A

Here is the subtree for one of the offending heroes: Hero tag: A state: _HeroState#d0a27 When the exception was thrown, this was the stack:

0 Hero._allHeroesFor.inviteHero. (package:flutter/src/widgets/heroes.dart:265:11)

1 Hero._allHeroesFor.inviteHero (package:flutter/src/widgets/heroes.dart:276:8)

2 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:295:21)

3 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5433:14)

4 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:308:15)

1
Are you sure prodName is unique?user13608781
@Jot yes i have given different names everytime...do A1 and A2 count different as strings right? If yes then yes they are uniqueAditya Pandey
Do you have multiple FloatingActionButtons defined somewhere? I tried your sample code and it works fine for me.gugge
I have no FloatingActionButton in my entire project but still getting this error when I navigate from child to parent screen. Please suggest me what is the solution? Thanks a lot.Kamlesh

1 Answers

0
votes

I have sorted out the problem. As @Jot said prodname wasn't unique in every case plus i made a similar horizontal list using the same data hence it created an error. So upon entering unique prodname like a1, a2 or a,b,c the error was removed.