Home > Net >  Flutter error ErrorSummary('There are multiple heroes that share the same tag within a subtree.
Flutter error ErrorSummary('There are multiple heroes that share the same tag within a subtree.

Time:05-23

Hello im getting that error whenever i press a card generated from the data retrieved from db but not when they're hardcoded.

List<Product> products = [];
void _getProduct() {
db.getConnection().then((conn) {
  String sql = 'select * from product;';
  conn.query(sql).then((results) {
    for (var row in results) {
      if (count < 5) {
        products.add(Product(
            'assets/headphones_2.png',
            row['prodName'].toString(),
            row['description'].toString(),
            row['price']));
        count  ;
      } else {}
    }
  });
  conn.close();
  setState(() {});
});
}

This is the get product function which is called in the inistate.

SliverToBoxAdapter(
                  child: ProductList(
                    products: products,
                  ),
                ),

The products variable is passed to another class here.

child: Swiper(
    itemCount: products.length,
    itemBuilder: (_, index) {
      return ProductCard(
          height: cardHeight, width: cardWidth, product: products[index]);
    },

This is the product cards generated

 return InkWell(
  onTap: () => Navigator.of(context).push(
      MaterialPageRoute(builder: (_) => ProductPage(product: product))),

This is the navigator code in the ProductList class and whenever I press on a card generated, i get the error mentioned.

throw FlutterError.fromParts(<DiagnosticsNode>[
        ErrorSummary('There are multiple heroes that share the same tag within a subtree.'),
        ErrorDescription(
          'Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), '
          'each Hero must have a unique non-null tag.\n'
          'In this case, multiple heroes had the following tag: $tag',
        ),
        DiagnosticsProperty<StatefulElement>('Here is the subtree for one of the offending heroes', hero, linePrefix: '# ', style: DiagnosticsTreeStyle.dense),
      ]);

CodePudding user response:

The issue supposed to be in ProductPage(), are you using Hero widget in ProductPage() ?

CodePudding user response:

This is commonly caused when using the Hero widget and also with the FloatingActionButton. You have to look at ProductPage for fix this.

  • Related