【发布时间】:2018-02-26 05:39:45
【问题描述】:
我在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 放在 Row 或 Column 小部件中,而不是放在 appBar 中,它也无法再次工作。
答案:
感谢 siva Kumar,我在调用函数时出错了,我们应该这样调用它:
onPressed: _onSearchButtonPressed, // without parenthesis.
或者这样:
onPressed: (){
_onSearchButtonPressed();
},
【问题讨论】: