【发布时间】:2023-03-31 16:59:02
【问题描述】:
我无法设置 fn changedDetail 的值
当我点击 ontap 时,我想在 fn changedDetail 中设置值!= null icon Function(bool) changedDetail ;
在有状态的第二个小部件中
Function(bool) changedDetail ;
处于状态第二个小部件
Expanded(
flex: 1,
child: InkWell(
onTap: () {
setState(() {
return this.widget.changedDetail(false);
});
},
child: Container(
padding: EdgeInsets.only(top: 12.0),
child: Icon(
FontAwesomeIcons.thLarge,
color: KwanjaiColors.grey3,
)),
),
),
Expanded(
flex: 1,
child: InkWell(
onTap: () {
setState(() {
return this.widget.changedDetail(true);
});
},
child: Container(
padding: EdgeInsets.only(top: 12.0),
child: Icon(
FontAwesomeIcons.thList,
color: KwanjaiColors.grey3,
)),
),
),
在父母中
bool clicktap = false;
bool choiceTap = false;
tapFn(bool choice) {
setState(() {
choice == true ? choiceTap = true : choiceTap = false;
});
}
在小部件父级中
body: Column(children: <Widget>[
Container(
child: new ProjectIndexTab(changedDetail: tapFn(clicktap)),
),
Expanded(
child: Container(
color: KwanjaiColors.bg,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
child: Column(children: <Widget>[
Container(child: ProjectIndexWorkDaily()),
Expanded(
// cuz has gridview must have expanded !!!!
child: Column(children: <Widget>[
Expanded(
child: choiceTap == true
? ProjectViewList()
: ProjectGridList())
]),
),
]),
),
),
),
])
日志
I/flutter (12900):引发了另一个异常:NoSuchMethodError:方法“调用”在 null 上被调用。
【问题讨论】:
标签: flutter dart flutter-dependencies