1
votes

I'm Working on app, and i'm navigating through pages using routes, i'm not using any hero or FloatingActionButtons but i'm getting this hero related error, does anybody has any idea what could be the cause of that?

Here's the navigation call

nextTapped()async{
    if(occasionTitleTxtField.text.isEmpty || dateTxtField.text.isEmpty || detailsTxtField.text.isEmpty)
      ErrorOverlay("Invalid Data", false);
    else
      {
        await LoadingOverlay.of(context).during(UserOperations().createFirstOccasion(context, occasionTitleTxtField.text, dateTxtField.text, detailsTxtField.text, repeatEveryYear, timeLimit)).then((value){
          if(value.elementAt(0) == "true")
              Navigator.of(context).pushReplacementNamed('/firstGift',arguments: FirstGiftPage(value.elementAt(1),occasionTitleTxtField.text));
        });
      }
  }

Here's the route_generator

class RouteGenerator {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    // Getting arguments passed in while calling Navigator.pushNamed
    final args = settings.arguments;

    switch (settings.name) {
      case '/':
        return MaterialPageRoute(builder: (_) => SplashScreen());
      case '/login':
        return MaterialPageRoute(builder: (_) => LoginPage());
      case '/homepage':
        return MaterialPageRoute(builder: (_) => HomePage());
      case '/signUp':
        return MaterialPageRoute(builder: (_) => SignUpScreen());
      case '/otpScreen':
        return MaterialPageRoute(builder: (_) {
          OTPScreen screenArgs = args;
          return OTPScreen(screenArgs.phoneNumber,screenArgs.countryCode);
        });
      case '/phoneNumber':
        return MaterialPageRoute(builder: (_) {
          PhoneNumberScreen screenArgs = args;
          return PhoneNumberScreen(screenArgs.Provider);
        });
      case '/interests':
        return MaterialPageRoute(builder: (_) => InterestsPage());
      case '/invitation':
        return MaterialPageRoute(builder: (_) => InvitationPage());
      case '/firstOccasion':
        return MaterialPageRoute(builder: (_) => FirstOccasion());
      case '/firstGift':
        return MaterialPageRoute(builder: (_) {
          FirstGiftPage screenArgs = args;
          return FirstGiftPage(screenArgs.occasionID,screenArgs.occasionTitle);
        });
      case '/map':
        return MaterialPageRoute(builder: (_) => MapsPage());
      default:
        return _errorRoute();
    }
  }

  static Route<dynamic> _errorRoute() {
    return MaterialPageRoute(builder: (_) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Error'),
        ),
        body: Center(
          child: Text('UnderConstruction'),
        ),
      );
    });
  }
}

Page i want to navigate to

class FirstGiftPage extends StatefulWidget {
  String occasionID;
  String occasionTitle;
  static LatLng storeLocation;
  FirstGiftPage(this.occasionID,this.occasionTitle);
   @override
  _FirstGiftPageState createState() => _FirstGiftPageState();
}

class _FirstGiftPageState extends State<FirstGiftPage> {
  TextEditingController giftTitleTxtField = TextEditingController();
  TextEditingController giftLinkTxtField = TextEditingController();
  TextEditingController giftPriceTxtField = TextEditingController();
  TextEditingController giftStoreAddTxtField = TextEditingController();
  int giftCounter = 0;
  TextEditingController detailsTxtField = TextEditingController();
  Future<File> imageFile;


  nextTapped()async{
    if(giftTitleTxtField.text.isEmpty || giftLinkTxtField.text.isEmpty || giftPriceTxtField.text.isEmpty || detailsTxtField.text.isEmpty)
      ErrorOverlay("Invalid Data",false);
    else
      {
        Map<String,dynamic> giftData={
          "giftName" : giftTitleTxtField.text,
          "giftLink" : giftLinkTxtField.text,
          "giftPrice" : giftPriceTxtField.text,
          "storeAddress": giftStoreAddTxtField.text,
          "details" : detailsTxtField.text,
          "giftQuantity" : giftCounter,
          "images":[imageFile.toString()],
          "occasionID": widget.occasionID
        };
        ErrorOverlay("Gift Done",true);
        Navigator.of(context).pushReplacementNamed("/homepage");
      }
  }

  showMaps(){
    Navigator.of(context).pushNamed("/map");
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          gradient: LinearGradient(
              colors: [
                Color.fromRGBO(246, 76, 77, 1),
                Color.fromRGBO(156, 51, 117, 1)
              ],
              begin: Alignment .topRight,
              end: Alignment.bottomLeft
          )
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar:AppBar(
          automaticallyImplyLeading: false,
          backgroundColor: Colors.transparent,
          elevation: 0,
          bottom: PreferredSize(
            preferredSize: Size(0.0, 80.0),
            child: Padding(
              //TODO::Change padding to ScreenWidth - 300 / 2
              padding: const EdgeInsets.only(left: 55.0 ,right: 55.0,bottom: 30.0),
              child: Text(AppLocalizations.of(context).firstGift,style: TextStyle(color: Colors.white,fontSize: 30.0),textAlign: TextAlign.center,maxLines: 2,),
            ),
          ),
        ),
        body: Padding(
          padding: const EdgeInsets.only(top: 20.0,left: 15.0,right: 15.0),
          child: Align(
            alignment: Alignment.topCenter,
            child: Column(
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextFormField(
                    controller: giftTitleTxtField,
                    obscureText: false,
                    decoration: InputDecoration(
                        filled: true,
                        fillColor: Colors.white,
                        contentPadding:EdgeInsets.only(top:20.0,bottom:20.0,left: 15.0),
                        hintText: AppLocalizations.of(context).giftName,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        prefix: Container(width: 10.0,),
                        hintStyle: TextStyle(
                          fontWeight: FontWeight.w600,
                          fontSize: 16,
                        )
                    ),),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextFormField(
                    controller: giftLinkTxtField,
                    obscureText: false,
                    decoration: InputDecoration(
                        filled: true,
                        fillColor: Colors.white,
                        contentPadding:EdgeInsets.only(top:20.0,bottom:20.0,left: 15.0),
                        hintText: AppLocalizations.of(context).giftLink,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        prefix: Container(width: 10.0,),
                        hintStyle: TextStyle(
                          fontWeight: FontWeight.w600,
                          fontSize: 16,
                        )
                    ),),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextFormField(
                    controller: giftPriceTxtField,
                    obscureText: false,
                    decoration: InputDecoration(
                        filled: true,
                        fillColor: Colors.white,
                        contentPadding:EdgeInsets.only(top:20.0,bottom:20.0,left: 15.0),
                        hintText: AppLocalizations.of(context).giftPrice,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        prefix: Container(width: 10.0,),
                        hintStyle: TextStyle(
                          fontWeight: FontWeight.w600,
                          fontSize: 16,
                        )
                    ),),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextFormField(
                    readOnly: true,
                    onTap: showMaps,
                    controller: giftStoreAddTxtField,
                    obscureText: false,
                    decoration: InputDecoration(
                        filled: true,
                        fillColor: Colors.white,
                        contentPadding:EdgeInsets.only(top:20.0,bottom:20.0,left: 15.0),
                        hintText: AppLocalizations.of(context).giftStoreAdd,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(30.0),
                        ),
                        hintStyle: TextStyle(
                          fontWeight: FontWeight.w600,
                          fontSize: 16,
                        )
                    ),),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Text(AppLocalizations.of(context).giftQuantity,style: TextStyle(color: Colors.white),),
                      ),
                      Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Counter(
                          initialValue: giftCounter,
                          minValue: 0,
                          maxValue: 10,
                          step: 1,
                          decimalPlaces: 0,
                          textStyle: TextStyle(color: Colors.white),
                          onChanged: (value) { // get the latest value from here
                            setState(() {
                              giftCounter = value;
                            });
                          },
                        ),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextFormField(
                    enabled: false,
                    obscureText: false,
                    decoration: InputDecoration(
                        filled: true,
                        fillColor: Colors.white,
                        contentPadding: EdgeInsets.only(top: 20),
                        hintText: widget.occasionTitle,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                        prefix: Container(width: 10.0,),
                        hintStyle: TextStyle(
                          fontWeight: FontWeight.w600,
                          fontSize: 16,
                        )
                    ),),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: TextFormField(
                    maxLines: null,
                    textAlign: TextAlign.center,
                    textAlignVertical: TextAlignVertical.center,
                    controller: detailsTxtField,
                    obscureText: false,
                    decoration: InputDecoration(
                        filled: true,
                        fillColor: Colors.white,
                        contentPadding: EdgeInsets.only(top: 20),
                        hintText: AppLocalizations.of(context).details,
                        border: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white,
                              width: 1
                          ),
                          borderRadius: BorderRadius.circular(20.0),
                        ),
                        prefix: Container(width: 10.0,),
                        hintStyle: TextStyle(
                            fontWeight: FontWeight.w600,
                            fontSize: 16,
                            height: 4.0
                        )
                    ),),
                ),
                InkWell(
                  onTap: null,
                  child: Align(
                    alignment: Alignment.centerRight,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Container(
                        width: 50.0,
                        height: 50.0,
                        padding: const EdgeInsets.all(8.0),
                        decoration: BoxDecoration(
                          border: Border.all(color: Colors.white,width: 4.0),
                          borderRadius: BorderRadius.circular(2.0)
                        ),
                        child: Center(
                          child: Icon(Icons.camera_alt_outlined,color: Colors.white,size: 25.0,),
                        ),
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
        bottomNavigationBar: BottomAppBar(
          child: Container(
            child: Wrap(
              //mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Align(
                    alignment: MyApp.getLocale(context).languageCode == "ar" ? Alignment.centerLeft:Alignment.centerRight,
                    child: Text("(4/5)"),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(8.0),
                    child: LinearProgressIndicator(
                      minHeight: 10.0,
                      backgroundColor: Colors.white,
                      value: 0.80,
                      valueColor: AlwaysStoppedAnimation<Color>(Colors.orange),
                    ),
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: InkWell(
                          onTap: (){
                            Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (BuildContext context)=> FirstGiftPage("","")));
                          },
                          child: Text(AppLocalizations.of(context).ignore,style: TextStyle(decoration: TextDecoration.underline),)),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: InkWell(
                        onTap: nextTapped,
                        child: Container(
                          width: 80.0,
                          padding: EdgeInsets.all(8.0),
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(10.0),
                              gradient: LinearGradient(
                                  colors: [
                                    Color.fromRGBO(246, 76, 77, 1),
                                    Color.fromRGBO(156, 51, 117, 1)
                                  ],
                                  begin: Alignment .topRight,
                                  end: Alignment.bottomLeft
                              )
                          ),
                          child: Center(child: Text(AppLocalizations.of(context).next, style: TextStyle(color: Colors.white),)),
                        ),
                      ),
                    )
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Here's the error

════════ 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:

Here is the subtree for one of the offending heroes: Hero tag: state: _HeroState#48fb7 When the exception was thrown, this was the stack: #0 Hero._allHeroesFor.inviteHero. >(package:flutter/src/widgets/heroes.dart:268:11) #1 Hero._allHeroesFor.inviteHero (package:flutter/src/widgets/heroes.dart:279:8) #2 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:298:21) #3 SingleChildRenderObjectElement.visitChildren >(package:flutter/src/widgets/framework.dart:6105:14) #4 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15) ... ════════════════════════════════════════════════════════════════════════════════════════════════════

2
are you using floating action buttons>griffins
No, not even one, or any hero animationsFarah Makhlouf

2 Answers

0
votes

If you are using more than one floating action button then you need to pass your own tag to each button like this

FloatingActionButton(
    heroTag: "tag1",
)

FloatingActionButton(
    heroTag: "tag2",
)

By default, the heroTag is tag so in this case, you will get an error.

Second thing

If you are using more than one hero animation widget on the same page and share the same tag then also same error exist so you need to pass your own tag to each Hero widget

0
votes

I solved this by creating a new file for the page i want to navigate to and it worked, have no idea how