标签: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