rafalbednarczuk / curved_navigation_bar

Animated Curved Navigation Bar in Flutter
BSD 2-Clause "Simplified" License
694 stars 242 forks source link

Getting error "There are multiple heroes that share the same tag within a subtree" at compile time #103

Closed kamleshwebtech closed 3 years ago

kamleshwebtech commented 3 years ago

I am getting below error at the time of compile and running this curved_navigation_bar example while I am not using any herotag in my entire app:

════════ Exception caught by scheduler library ═════════════════════════════════
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: <SnackBar Hero tag - Text("Welcome Riya Ji!")>
Here is the subtree for one of the offending heroes: Hero
    tag: <SnackBar Hero tag - Text("Welcome Riya Ji!")>
    state: _HeroState#f368c
When the exception was thrown, this was the stack
#0      Hero._allHeroesFor.inviteHero.<anonymous closure>
package:flutter/…/widgets/heroes.dart:256
#1      Hero._allHeroesFor.inviteHero
package:flutter/…/widgets/heroes.dart:267
#2      Hero._allHeroesFor.visitor
package:flutter/…/widgets/heroes.dart:286
#3      ComponentElement.visitChildren
package:flutter/…/widgets/framework.dart:4549
#4      Hero._allHeroesFor.visitor
package:flutter/…/widgets/heroes.dart:301
...
════════════════════════════════════════════════════════════════════════════════

Kindly suggest what is the issue and how can we solve it. Thanks a lot.

kamleshwebtech commented 3 years ago

I did some research from main.dart to landing page where I implemented curved_navigation_bar package and found that I ran into same problem and fixed it by removing SnackBar before any call to Navigator with ScaffoldMessenger.of(context).removeCurrentSnackBar().

Look like this with Sample code:

ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('A SnackBar has been shown.'),
          animation: null,
        ),
      );
ScaffoldMessenger.of(context).removeCurrentSnackBar();
Navigator.pushReplacementNamed(context, '/dashboard');

Hope it'll work for you.

FYI It was happening due to SnackBar's animation. I have set it to null "animation: null," and it worked. Thanks.