码迷,mamicode.com
首页 > 其他好文 > 详细

Flutter踩坑记: There are multiple heroes that share the same tag within a subtree.

时间:2020-03-16 12:54:19      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:widget   tco   multi   sse   pre   divide   ESS   cal   tom   

There are multiple heroes that share the same tag within a subtree.

Flutter首页里加了脚手架里的加号按钮floatingActionButton,页面结构大致是这样,从上往下依次是appBar,ListView,floatActionButton..,在listView的item里面的一个点击回调的事件里做页面跳转,一跳转就是黑屏,这个问题折腾了许久,主要花在了排查问题上,排查了路由设置问题和类名以及页面结构等问题之后还是无果,最后拿控制台的一句话"There are multiple heroes that share the same tag within a subtree."粘贴到google上出来了一些结果,问题根源在于FloatingActionButton的一个属性标识即heroTag没有设置,要手动设置一个标识唯一即可


Provide<MyCounter>(
      builder: (context, child, val) {
        int currentCount = Provide.value<MyCounter>(context).currentCount;
        return Scaffold(
          appBar: AppBar(
            title: Text("首页 $currentCount", style: TextStyle(color: Colors.white)),
            flexibleSpace: Container(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [Colors.blue[100], Colors.blue[300], Colors.blue],
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter),
              ),
            ),
          ),
          body: Container(
              child: ListView.builder(
            itemCount: dataList.length,
            itemBuilder: (BuildContext context, int index) {
              String name = dataList[index].name;
              Function callBack = dataList[index].tapCallBack;
              return Column(
                children: <Widget>[
                  ListTile(
                    title: Text(name),
                    onTap: callBack,
                  ),
                  Divider(),
                ],
              );
            },
          )),
          floatingActionButton: FloatingActionButton(
            heroTag: "你大爷的", //就是这个玩意儿
            child: Icon(Icons.add, color: Colors.white, size: 44),
            backgroundColor: Colors.blueAccent,
            onPressed: () {
              Provide.value<MyCounter>(context).updateCount(currentCount);
            },
          ),
        );
      },
    );

参考博文
Flutter: There are multiple heroes that share the same tag within a subtree异常
flutter 跳转报错:There are multiple heroes that share the same tag within a subtree.

Flutter踩坑记: There are multiple heroes that share the same tag within a subtree.

标签:widget   tco   multi   sse   pre   divide   ESS   cal   tom   

原文地址:https://www.cnblogs.com/wgb1234/p/12502860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!