扑。多个英雄共享同一标签。带按钮的ListView

时间:2020-08-22 09:45:18

标签: flutter listview dart gesturedetector

无法弄清楚如何解决此问题。因此,这是代表我的问题的最简单的代码:

   Scaffold(
      body: Stack(
        children: <Widget>[
          ...
          Scrollbar(
            child: ListView.builder(
              primary: false,
              shrinkWrap: true,
              itemCount: _mapBloc?.mapData?.companies?.count ?? 0,
              itemBuilder: (context, index) {
                final company = _mapBloc?.mapData?.companies?.data[index];
                return InkWell(
                  child: Hero(
                    tag: company.id,
                    child: Card(
                      child: Container(
                        height: 50,
                        width: double.infinity,
                      ),
                    ),
                  ),
                  onTap: () {
                    Navigator.of(context)
                        .pushNamed('/company', arguments: company)
                        .then(
                      (results) {
                        if (results is PopWithResults) {
                          PopWithResults popResult = results;
                        }
                      },
                    );
                  },
                );
              },
            ),
          )
        ],
      ),
    );

堆栈跟踪:

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.
...

ListView中的项目计数随每个数据库请求而变化。如果在ListView中,小部件的大小最多为5个,则在列表扩展到例如8个元素后,单击即可正常工作,我得到上面写的错误。用什么可以连接?我尝试使用唯一的Hero标签,但这不能解决问题。

我需要一些建议,希望您能帮助我。如果您需要更多信息,请写评论。

感谢您的关注!

0 个答案:

没有答案