有多名英雄在同一子树内共享相同的标签。在每个要进行动画的子树中。

huangapple go评论77阅读模式
英文:

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

问题

这是您提供的代码的翻译部分:

错误出现在每次单击Google登录按钮时。在此输入图像描述。在输入Google登录按钮后,应将用户导航到底部导航栏在此输入图像描述。如果用户没有注销,应用程序将保存令牌,用户将直接访问底部导航栏,无需再次进行Google登录...我该如何解决?

异常已发生。
FlutterError(在子树内有多个共享相同标签的英雄。
在每个要对英雄进行动画处理的子树中(即PageRoute子树),每个Hero必须具有唯一的非空标签
在这种情况下,多个英雄具有以下标签:<默认的浮动操作按钮标签>
#以下是其中一个有问题的英雄的子树:Hero

Google登录页面代码
```dart
import 'package:firebase_auth/firebase_auth.dart';
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 = [
      // 第2页
      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',
                        ),
                        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),
                            ),
                          ),
                          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,
        ),
      ),
    );
  }
}

底部导航栏代码

import 'package:flutter/material.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:recipe_collector/All Recipes/viewpage.dart';
import 'package:recipe_collector/OCR/OCR_Page.dart';
import 'package:recipe_collector/Profile/Profile.dart';
import 'package:

<details>
<summary>英文:</summary>

This error occur whenever i click the Google Sign-In button. [enter image description here][1]. After entering the google sign-in button, it should navigate the user to a bottom navigation bar [enter image description here][2]. If the user haven&#39;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: &lt;default FloatingActionButton tag&gt;
    # Here is the subtree for one of the offending heroes: Hero)

google sign-in page code
```import &#39;package:firebase_auth/firebase_auth.dart&#39;;
import &#39;package:flutter/material.dart&#39;;
import &#39;dart:math&#39; as math;
import &#39;package:liquid_swipe/liquid_swipe.dart&#39;;
import &#39;package:recipe_collector/Authen/Google_SignIn.dart&#39;;
import &#39;package:recipe_collector/BottomNavigationBar.dart&#39;;
import &#39;package:provider/provider.dart&#39;;
import &#39;package:recipe_collector/globalVariable.dart&#39; as global;
import &#39;package:custom_clippers/custom_clippers.dart&#39;;

import &#39;../OCR/OCR_Page.dart&#39;;

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

  @override
  State&lt;MyliquidSwipe&gt; createState() =&gt; _MyliquidSwipeState();
}

class _MyliquidSwipeState extends State&lt;MyliquidSwipe&gt;{



  @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(
                    &#39;assets/IntroPage/Tip Ingredient for Health Hint.png&#39;,
                  ),
                  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(
                        &#39;Welcome To&#39;,
                        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(
                        &#39;Recipes Collector&#39;,
                        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(
                      &#39;assets/IntroPage/TIFH.png&#39;,
                    ),
                    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(
                          &#39;assets/IntroPage/Intro Tag.png&#39;,
                        ),
                        // alignment: Alignment.center,
                        height: MediaQuery.of(context).size.height * 0.1,
                        width: MediaQuery.of(context).size.width * 0.85,
                        fit: BoxFit.fill,
                      ),
                    ),
                    Text(&#39;Tip Ingredient for Health Hint&#39;,
                        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&lt;
                                RoundedRectangleBorder&gt;(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: () =&gt;
                              googleSignIn().whenComplete(() async {
                            FirebaseUser user =
                                await FirebaseAuth.instance.currentUser();
                            Navigator.of(context).pushReplacement(
                                MaterialPageRoute(
                                    builder: (context) =&gt; 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(
                                        &#39;http://pngimg.com/uploads/google/google_PNG19635.png&#39;,
                                        fit: BoxFit.cover),
                                  ),
                                ),
                                SizedBox(
                                  width: 15,
                                ),
                                Text(&quot;Let&#39;s Start With Google !&quot;,
                                    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 &#39;package:convex_bottom_bar/convex_bottom_bar.dart&#39;;
import &#39;package:recipe_collector/All%20Recipes/viewpage.dart&#39;;
import &#39;package:recipe_collector/OCR/OCR_Page.dart&#39;;
import &#39;package:recipe_collector/Profile/Profile.dart&#39;;
import &#39;package:recipe_collector/Recipes%20Collection/RecipeSearch.dart&#39;;
import &#39;package:recipe_collector/Recipes%20Collection/recipe_collection_home.dart&#39;;
import &#39;package:recipe_collector/BottomNavigationBar.dart&#39;;
import &#39;BuyingList/cartHome.dart&#39;;
class BottomNav extends StatefulWidget {
const BottomNav({super.key});
@override
// _BottomNavState createState() =&gt; _BottomNavState();
State&lt;BottomNav&gt; createState() =&gt; _BottomNavState();
}
class _BottomNavState extends State&lt;BottomNav&gt; {
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: &#39;All&#39;),
TabItem(icon: Icons.explore, title: &#39;Collection&#39;),
TabItem(icon: Icons.edit_note_rounded, title: &#39;OCR&#39;),
TabItem(icon: Icons.message, title: &#39;Grocery&#39;),
TabItem(icon: Icons.perm_contact_cal, title: &#39;Profile&#39;),
],
initialActiveIndex: 2, //optional, default as 0
onTap: (int i) {
setState(() {
_currentindex = i;
});
})),
);
}
}```
</details>
# 答案1
**得分**: 0
Hero widget的heroTag必须是唯一的标签。如果您复制它,将会引发此错误。
<details>
<summary>英文:</summary>
Hero widget heroTag must be a unique tag. if you duplicate it, will throw this error. 
</details>
# 答案2
**得分**: 0
如果您的代码中有多个 `FloatingActionButton`,请将它们的 `heroTag` 属性设置为不同的值(字符串)。
<details>
<summary>英文:</summary>
If you have more than one `FloatingActionButton` in your code, set their `heroTag` attributes to different values(String). 
</details>

huangapple
  • 本文由 发表于 2023年4月4日 18:05:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75928091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定