Mne*_*oee 2 android click ios flutter
我在Scaffold
appBar中将一个widget列表作为动作,但是当我按下它们时它们没有响应,我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");
}
Run Code Online (Sandbox Code Playgroud)
即使我把IconButton放在一个Row
或Column
小部件中,而不是在其中appBar
,它也不再起作用.
答:
感谢siva Kumar,我在调用函数时遇到了错误,我们应该这样调用它:
onPressed: _onSearchButtonPressed, // without parenthesis.
Run Code Online (Sandbox Code Playgroud)
或者这样:
onPressed: (){
_onSearchButtonPressed();
},
Run Code Online (Sandbox Code Playgroud)
请尝试我的回答它会工作.
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");
}
Run Code Online (Sandbox Code Playgroud)