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 Hero tag for Cupertino navigation bars with navigator NavigatorState#ee56c(tickers: tracking 2 tickers)
Here is the subtree for one of the offending heroes: Hero
tag: Default Hero tag for Cupertino navigation bars with navigator NavigatorState#ee56c(tickers: tracking 2 tickers)
state: _HeroState#150ea
-------------------------------------------------------------------
实现功能:在列表页面点击单元格push到详情页面时报错。
从错误详情中可以获取到是因为Hero tag重复造成的。(Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), each Hero must have a unique non-null tag.)奇怪的是项目中就没有使用过Hero功能,为什么会报重复错误呢?
从更进一步的错误信息中捕捉到和navigator有关系(Default Hero tag for Cupertino navigation bars with navigator NavigatorState#ee56c(tickers: tracking 2 tickers))。项目选用的是Cupertino风格,确实使用到了navgation,赶紧把每个模块的pageWidget中的navigationBar都配置一遍,如下:
pageWidget配置navigation每个page模块的 navitaionBar中都配置了不同的heroTag值。然后运行发现还是报该错误;这就奇怪了,再继续找项目中的navigationBar,最后再main.dart中找到了原因。在搭建项目结构的时候,CupertinoTabBar构建每一个CupertinoPageScaffold时,统一添加了navigationBar,并且没有进行HeroTag区分。
CupertinoTabBar构建CupertinoPageScaffold的错误配置最后,都每一个navigationBar进行了heroTag区分,问题成功解决!
网友评论