There are multiple heroes that share the same tag within a subtree.
情况一:报错由于FloatingActionButton的heroTag引起的,看源码注释:
/// If this is not explicitly set, then there can only be one
/// [FloatingActionButton] per route (that is, per screen), since otherwise
/// there would be a tag conflict (multiple heroes on one route can't have the
/// same tag). The material design specification recommends only using one
/// floating action button per screen.
final Object heroTag;
大意是:如果没有显示设置FloatingActionButton 的heroTag 则一个页面只允许有一个FloatingActionButton,否则就会报上述错误.
解决办法:设置 FloatingActionButton的heroTag 为null;
情况二:报错是由于 CupertinoNavigationBar 的heroTag引起的,CupertinoNavigationBar使用在了tab页面,且页面实现了AutomaticKeepAliveClientMixin接口,但是不能设置heroTag为null,所有设置transitionBetweenRoutes:false即可。
/// Defaults to a common tag between all [CupertinoNavigationBar] and
/// [CupertinoSliverNavigationBar] instances of the same [Navigator]. With the
/// default tag, all navigation bars of the same navigator can transition
/// between each other as long as there's only one navigation bar per route.
///
/// This [heroTag] can be overridden to manually handle having multiple
/// navigation bars per route or to transition between multiple
/// [Navigator]s.
///
/// Cannot be null. To disable Hero transitions for this navigation bar,
/// set [transitionBetweenRoutes] to false.
/// {@endtemplate}