我把一个小部件列表作为动作在Scaffold appBar中,但是当我按下它们时它们没有响应,我在场景中也有一个floatingButton并且它完美地工作.
appBar: new AppBar(
title: new Text(
widget.title,
style: new TextStyle(
fontFamily: 'vazir'
),
),
centerTitle: true,
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onpressed: _onSearchButtonpressed(),
),
],
),
void _onSearchButtonpressed() {
print("search button clicked");
}
即使我将IconButton放在一个行或列小部件中,而不是在appBar中,它也无法再次运行.
回答:
感谢siva Kumar,我在调用函数时遇到了错误,我们应该以这种方式调用它:
onpressed: _onSearchButtonpressed, // without parenthesis.
或者这样:
onpressed: (){
_onSearchButtonpressed();
},
解决方法:
请尝试我的回答它会工作.
appBar: new AppBar(
title: new Text(
widget.title,
style: new TextStyle(
fontFamily: 'vazir'
),
),
centerTitle: true,
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onpressed: (){_onSearchButtonpressed();},
),
],
),
void _onSearchButtonpressed() {
print("search button clicked");
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。