当我从小部件导航到另一个小部件时,我遇到了这个问题,我进行了搜索,发现我应该用(FloatActionButton)添加(heroTag),但是我没有这个小部件, 这是问题消息:
══╡ 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: <default FloatingActionButton tag>
├# Here is the subtree for one of the offending heroes: Hero
When the exception was thrown, this was the stack:
#0 Hero._allHeroesFor.inviteHero.<anonymous closure> (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:5861:14)
#4 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#5 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#6 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#7 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#8 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#9 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#10 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#11 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#12 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#13 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#14 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#15 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#16 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#17 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#18 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#19 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#20 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#21 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#22 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#23 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#24 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#25 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#26 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#27 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#28 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#29 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#30 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#31 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#32 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#33 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#34 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#35 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#36 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#37 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#38 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#39 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#40 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#41 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#42 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#43 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#44 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#45 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#46 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#47 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#48 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#49 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#50 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#51 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#52 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#53 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#54 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#55 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#56 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#57 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#58 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#59 List.forEach (dart:core-patch/growable_array.dart:302:8)
#60 SliverMultiBoxAdaptorElement.visitChildren (package:flutter/src/widgets/sliver.dart:1312:36)
#61 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#62 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#63 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#64 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#65 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#66 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#67 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#68 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#69 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#70 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#71 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#72 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#73 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#74 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#75 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#76 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#77 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#78 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#79 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#80 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#81 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#82 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#83 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#84 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#85 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#86 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#87 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#88 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#89 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#90 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#91 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#92 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#93 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#94 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#95 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#96 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#97 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#98 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#99 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#100 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#101 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#102 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#103 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#104 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#105 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#106 _LayoutBuilderElement.visitChildren (package:flutter/src/widgets/layout_builder.dart:70:14)
#107 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#108 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#109 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#110 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#111 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#112 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#113 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#114 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#115 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#116 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#117 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#118 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#119 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#120 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#121 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#122 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#123 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#124 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#125 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#126 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#127 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#128 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#129 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#130 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#131 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#132 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#133 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#134 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#135 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#136 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#137 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#138 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#139 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#140 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#141 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#142 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#143 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#144 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#145 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#146 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5973:16)
#147 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#148 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#149 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#150 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#151 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#152 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#153 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#154 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#155 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#156 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#157 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#158 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#159 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#160 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#161 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#162 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#163 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#164 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#165 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#166 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#167 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#168 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#169 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#170 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#171 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#172 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#173 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#174 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#175 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#176 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4600:14)
#177 Hero._allHeroesFor.visitor (package:flutter/src/widgets/heroes.dart:311:15)
#178 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5861:14)
#179 Element.visitChildElements (package:flutter/src/widgets/framework.dart:3174:5)
#180 Hero._allHeroesFor (package:flutter/src/widgets/heroes.dart:314:13)
#181 HeroController._startHeroTransition (package:flutter/src/widgets/heroes.dart:840:53)
#182 HeroController._maybeStartHeroTransition.<anonymous closure> (package:flutter/src/widgets/heroes.dart:815:11)
#183 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#184 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1064:9)
#185 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:972:5)
#189 _invoke (dart:ui/hooks.dart:253:10)
#190 _drawFrame (dart:ui/hooks.dart:211:3)
(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════════════════════════
Another exception was thrown: An exception was throw by _MapStream<User, MUser> listened by
════════ 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: <default FloatingActionButton tag>
这是我的代码,即使我删除路线,问题仍然存在 main.dart:
child: MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => Map(),
'/profile': (context) => Profile(), //todo-Osama: gives error!
'/addMakan': (context) => AddMakan(),
},
map.dart
Widget build(BuildContext context) {
MapState mapState = Provider.of<MapState>(context);
return Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
body: Stack(
children: [
//Loading(),
GoogleMap(
initialCameraPosition: initialCamera,
mapType: mapType,
markers: mapState.markers,
myLocationEnabled: true,
myLocationButtonEnabled: false,
zoomControlsEnabled: false,
onMapCreated: (GoogleMapController controller) async {
mapCompleter.complete(controller);
mapController = await mapCompleter.future;
},
onCameraMove: (CameraPosition position) {
mapCurrentCenter = position.target;
if (!userControlMapType) {
if ((mapType == MapType.normal && position.zoom >= 18.0) ||
(mapType == MapType.satellite && position.zoom < 18.0))
mapState.changeMapType();
}
},
),
Tiles(),
//TilesNew(), //todo-Osama: error here!
Buttons(),
Search(),
],
search.dart:我在map.dart内称呼它
Widget build(BuildContext context) {
return Positioned(
top: 36,
left: 10.0,
right: 10.0,
child: Container(
height: 50.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30.0),
),
child: Padding(
padding: const EdgeInsets.only(bottom: 4.0), //todo: ?
child: Row(
children: [
IconButton(
icon: Icon(Icons.account_circle, size: 34, color: Colors.blue[700]),
onPressed: () => Navigator.pushNamed(context, '/profile'),
),
Text('|', style: TextStyle(color: Colors.black26, fontSize: 36.0)),
profile.dart:仅配置文件有效,但是当我导航至该问题时
class Profile extends StatefulWidget {
static String tag = 'profile';
@override
_ProfileState createState() => _ProfileState();
}
class _ProfileState extends State<Profile> {
Auth _auth = Auth();
final GlobalKey<FormBuilderState> _fbKey = GlobalKey<FormBuilderState>();
bool titleHasError;
bool bodyHasError;
@override
Widget build(BuildContext context) {
MUser user = Provider.of<MUser>(context);
return Hero(
tag: Text("hero"),
child: Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.blueAccent,
elevation: 8.0,
title: Text('دخول / تسجيل / اسم عضو'),
),
body: Container(
padding: EdgeInsets.symmetric(vertical: 32.0, horizontal: 16.0),
child: FormBuilder(
key: _fbKey,
child: Center(
child: Column(
children: <Widget>[
SizedBox(height: 32.0),
答案 0 :(得分:0)
在不看到所有Hero标签引用的情况下很难说出问题出在哪里,我建议将所有Hero标签更改为String(不是Text('...'))并确保它们是唯一的。
例如,在ListView中,Hero标签可以是'$itemName+${itemIndex}'
更新:
Hero(
tag: "avatar-$index",
child: Image.network(
"https://picsum.photos/seed/$index/800",
fit: BoxFit.cover,
),
),
您必须在英雄对的两端使用相同的标签。
更新: 每次使用Hero小部件(Hero小部件提供Hero动画)时,都需要这样做。如果您不尝试制作Hero动画,请不要使用Hero小部件。
从您的profile.dart中删除Hero小部件。