美文网首页
Flutter报错:There are multiple her

Flutter报错:There are multiple her

作者: 豆大人007 | 来源:发表于2021-03-11 16:16 被阅读0次
    详情错误信息

    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区分,问题成功解决!

    相关文章

      网友评论

          本文标题:Flutter报错:There are multiple her

          本文链接:https://www.haomeiwen.com/subject/csqoqltx.html