按下时有什么方法可以更改 float 按钮图标吗?
代码:
var musicButton = new FloatingActionButton(
onPressed: (){
if(playerState == PlayerState.playing) {
//setState(() => child = new Icon(Icons.pause));
setState((){
child: new Icon(Icons.play_arrow);
});
pause();
} else if (playerState == PlayerState.paused){
setState((){
child: new Icon(Icons.pause);
});
play();
}
},
tooltip: 'Play Music',
child: new Icon(Icons.pause));
最佳答案
您可以仅使用状态变量在图标之间切换。
例子:
bool playing = false;
然后
var musicButton = new FloatingActionButton(
onPressed: (){
if(playerState == PlayerState.playing) {
setState((){
playing = false;
});
pause();
} else if (playerState == PlayerState.paused){
setState((){
playing = true;
});
play();
}
},
tooltip: 'Play Music',
child: playing?new Icon(Icons.pause):new Icon(Icons.play_arrow));
希望有所帮助!
关于dart - 按下时更改 float 按钮图标的方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48677140/