简体   繁体   English

按下按钮后更改按钮的外观?

[英]change the look of a button after it got pressed?

I am working on an app which makes use of different buttons.我正在开发一个使用不同按钮的应用程序。 How do I make a button "look pressed" and make it change to normal after I pressed a different button?如何使按钮“看起来被按下”并在按下其他按钮后使其变为正常状态? I am fairly new to flutter and I really struggle with this task.我对颤振相当陌生,我真的很难完成这项任务。

It should have the same function as the example on the picture.它应该与图片上的示例具有相同的功能。

例子

You can set a boolean field (such as _isSelected) for each button in the state class of the main StatefulWidget where the buttons exist.您可以为按钮所在的主 StatefulWidget 的状态类中的每个按钮设置一个布尔字段(例如 _isSelected)。 Then in the onPressed method, call setState to change the value to true.然后在 onPressed 方法中,调用 setState 将值更改为 true。 Then you can setup a ternary operator to switch between different button styles.然后你可以设置一个三元运算符来在不同的按钮样式之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM