英文:
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'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: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 = [
//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;
});
})),
);
}
}```
</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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论