I/flutter ( 8790): Another exception was thrown: There are multiple heroes that share the same tag within a subtree.
这是代码:
路由:
<String, WidgetBuilder>{
'/first':(BuildContext context) =>NavigatorOne() ,
'/second':(BuildContext context) =>NavigatorTwo(),
'/third':(BuildContext context) =>NavigatorThree(),
},
Navigator.of(context).pushNamed('/first');
Navigator.of(context).pushNamed('/second');
Navigator.of(context).pushNamed('/third');
class NavigatorOne extends StatefulWidget {
@override
_NavigatorOneState createState() => _NavigatorOneState();
}
class _NavigatorOneState extends State<NavigatorOne> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
color: Colors.green,
child: RaisedButton(child: Text(' one 1'),onPressed: (){
Navigator.of(context).pushNamed('/second');
},),
),
);
}
}
错误信息:
══╡ 调度器库捕获的异常 ╞═════════════════════════════════════════════════════════
I/flutter (21786): 调度回调期间抛出以下断言:
I/flutter (21786): 在子树中有多个共享相同标记的 Hero。
I/flutter (21786): 对于将要进行动画处理的每个子树(通常是一个PageRoute子树),每个Hero必须具有唯一的非空标记。
I/flutter (21786): 在本例中,多个hero具有以下标记:<默认浮动操作按钮标记>
如何解决?
Hero
的ListTile
中可能会出现类似的问题。这个Hero
不仅仅是一个,而是由你的items.length
数量所决定的,因此标记应该是'tag$index'
。 - mrahimygk