flutterdartgoogle-signinflutter-bottomnavigation

There are multiple heroes that share the same tag within a subtree. Within each subtree for which heroes are to be animated


This error occur whenever i click the Google Sign-In button. enter image description here. After entering the google sign-in button, it should navigate the user to a bottom navigation bar enter image description here. If the user haven't sign out, the app will save the token and the user will access the bottom navigation bar directly without required google sign in again...How can i solve it?

Exception has occurred.
FlutterError (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: <default FloatingActionButton tag>
# Here is the subtree for one of the offending heroes: Hero)

google sign-in page code

import 'package:flutter/material.dart';
import 'dart:math' as math;
import 'package:liquid_swipe/liquid_swipe.dart';
import 'package:recipe_collector/Authen/Google_SignIn.dart';
import 'package:recipe_collector/BottomNavigationBar.dart';
import 'package:provider/provider.dart';
import 'package:recipe_collector/globalVariable.dart' as global;
import 'package:custom_clippers/custom_clippers.dart';

import '../OCR/OCR_Page.dart';

class MyliquidSwipe extends StatefulWidget {
  const MyliquidSwipe({super.key});

  @override
  State<MyliquidSwipe> createState() => _MyliquidSwipeState();
}

class _MyliquidSwipeState extends State<MyliquidSwipe>{



  @override
  Widget build(BuildContext context) {
    final page = [
      //2rd page
      MaterialApp(home: Builder(builder: (BuildContext context) {
        return Scaffold(
          backgroundColor: Color.fromARGB(255, 185, 174, 151),
          body: Stack(
            children: [
              SizedBox(
                height: MediaQuery.of(context).size.height * 0.12,
              ),
              Container(
                child: Image(
                  image: AssetImage(
                    'assets/IntroPage/Tip Ingredient for Health Hint.png',
                  ),
                  alignment: Alignment.center,
                  height: double.infinity,
                  width: double.infinity,
                  fit: BoxFit.cover,
                ),
              ),
              Column(children: [
                SizedBox(
                  height: MediaQuery.of(context).size.height * 0.12,
                ),
                Padding(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 8.0, vertical: 3),
                  child: Align(
                      alignment: Alignment.bottomLeft,
                      child: Container(
                          child: Text(
                        'Welcome To',
                        style: TextStyle(
                            fontSize: displayWidth(context) * 0.06,
                            fontWeight: FontWeight.w300,
                            color: Color.fromARGB(255, 172, 152, 129)),
                      ))),
                ),
                Padding(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 8.0, vertical: 3),
                  child: Align(
                    alignment: Alignment.bottomLeft,
                    child: Container(
                      child: Text(
                        'Recipes Collector',
                        style: TextStyle(
                            fontSize: displayWidth(context) * 0.08,
                            fontWeight: FontWeight.w600,
                            color: Color.fromARGB(255, 172, 152, 129)),
                      ),
                    ),
                  ),
                ),
                SizedBox(
                  height: MediaQuery.of(context).size.height * 0.04,
                ),
                Container(
                  child: Image(
                    image: AssetImage(
                      'assets/IntroPage/TIFH.png',
                    ),
                    height: 310,
                    width: 310,
                    fit: BoxFit.fill,
                  ),
                ),
                SizedBox(
                  height: MediaQuery.of(context).size.height * 0.030,
                ),
                Stack(
                  alignment: Alignment.center,
                  children: [
                    Container(
                      child: Image(
                        image: AssetImage(
                          'assets/IntroPage/Intro Tag.png',
                        ),
                        // alignment: Alignment.center,
                        height: MediaQuery.of(context).size.height * 0.1,
                        width: MediaQuery.of(context).size.width * 0.85,
                        fit: BoxFit.fill,
                      ),
                    ),
                    Text('Tip Ingredient for Health Hint',
                        style: TextStyle(
                          fontSize: displayWidth(context) * 0.048,
                          fontWeight: FontWeight.w600,
                          color: Color.fromARGB(255, 51, 44, 25),
                        )),
                  ],
                ),
                SizedBox(
                  height: MediaQuery.of(context).size.height * 0.05,
                ),
                Align(
                    alignment: Alignment.bottomCenter,
                    child: SizedBox(
                        width: MediaQuery.of(context).size.width * 0.82,
                        height: MediaQuery.of(context).size.height * 0.07,
                        child: ElevatedButton(
                          style: ButtonStyle(
                            shape: MaterialStateProperty.all<
                                RoundedRectangleBorder>(RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(20),
                            )),
                            backgroundColor: MaterialStateProperty.all(
                              Color.fromARGB(255, 196, 192, 182),
                            ),
                          ),
                          The Error happen whenever i click the Google Sign-In Button
                          vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
                          onPressed: () =>
                              googleSignIn().whenComplete(() async {
                            FirebaseUser user =
                                await FirebaseAuth.instance.currentUser();
                            Navigator.of(context).pushReplacement(
                                MaterialPageRoute(
                                    builder: (context) => BottomNav()));
                            global.retrieveUserData();
                          }),
                          child: Padding(
                            padding: const EdgeInsets.all(5.0),
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Container(
                                  decoration: BoxDecoration(
                                      shape: BoxShape.circle,
                                      color: Colors.white),
                                  child: ClipRRect(
                                    child: Image.network(
                                        'http://pngimg.com/uploads/google/google_PNG19635.png',
                                        fit: BoxFit.cover),
                                  ),
                                ),
                                SizedBox(
                                  width: 15,
                                ),
                                Text("Let's Start With Google !",
                                    style: TextStyle(
                                      fontSize: displayWidth(context) * 0.045,
                                      fontWeight: FontWeight.w500,
                                      color: Color.fromARGB(255, 0, 0, 0),
                                    )),
                              ],
                            ),
                          ),
                        )))
              ]),
            ],
          ),
        );
      })),
    ];
    return MaterialApp(
      home: LiquidSwipe(
        enableLoop: false,
        pages: page,
        slideIconWidget: Icon(
          Icons.arrow_left_sharp,
          size: 30,
          color: Colors.white,
        ),
      ),
    );
  }
}

bottom navigation bar code

import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:recipe_collector/All%20Recipes/viewpage.dart';
import 'package:recipe_collector/OCR/OCR_Page.dart';
import 'package:recipe_collector/Profile/Profile.dart';
import 'package:recipe_collector/Recipes%20Collection/RecipeSearch.dart';
import 'package:recipe_collector/Recipes%20Collection/recipe_collection_home.dart';
import 'package:recipe_collector/BottomNavigationBar.dart';
import 'BuyingList/cartHome.dart';

class BottomNav extends StatefulWidget {
  const BottomNav({super.key});

  @override
  // _BottomNavState createState() => _BottomNavState();
  State<BottomNav> createState() => _BottomNavState();
}

class _BottomNavState extends State<BottomNav> {
  
  int _currentindex = 2;
    List pages = [RecipesViewPage(),RecipeCollectorHome(),OCRPage(),HomeCart(),Profile()];
  
  @override
  Widget build(BuildContext context) {
     return MaterialApp(
       home: Scaffold(
          body: pages[_currentindex],
          bottomNavigationBar: ConvexAppBar(
              style: TabStyle.reactCircle,
              backgroundColor: Color.fromARGB(255, 51, 44, 25),
              items: [
                TabItem(icon: Icons.travel_explore, title: 'All'),
                TabItem(icon: Icons.explore, title: 'Collection'),
                TabItem(icon: Icons.edit_note_rounded, title: 'OCR'),
                TabItem(icon: Icons.message, title: 'Grocery'),
                TabItem(icon: Icons.perm_contact_cal, title: 'Profile'),
              ],
              initialActiveIndex: 2, //optional, default as 0
              onTap: (int i) {
                setState(() {
                  _currentindex = i;
                });
              })),
     );
  }
}```

Solution

  • If you have more than one FloatingActionButton in your code, set their heroTag attributes to different values(String).