hoverColor property of the Raised button class in Flutter, doesn't change?

笑着哭i 提交于 2020-12-12 10:04:51

问题


Edit: I am using the IOS simulator, the following issue may not be persistent across all platforms.

I am under the impression that when creating a RaisedButton, it is possible to change the color of the button when the cursor hovers over the button.

However this does not appear to be the case.

// Create button

RaisedButton(
    onPressed: () {},
    color: Colors.redButtonBackgroundColo
    textColor: Colors.white,
    disabledColor: Colors.disabledRedButtonBackgroundColor,
    disabledTextColor: Colors.white,
    disabledElevation: 4,
    elevation: 4,
    hoverColor: Colors.redHoveredOverButtonColor, //<--- Here is where I would like to change the button color (to a slightly lighter shade.)
    padding: const EdgeInsets.all(14.0),      
 ),        

Thanks in advance for any help you may provide.


回答1:


Since the question is not very clear I am going to assume a few things. First, you are running the app on flutter desktop or web. In that case, the code should work perfectly fine.

If you are trying it on mobile, then there is no hover action on mobile, that's why the button would not change its color.

If you want to change the color on tap, then you can wrap the RaisedButton with a GestureDetector and use the onTap or onPanDown callback to manually change the color of the button.



来源:https://stackoverflow.com/questions/58011860/hovercolor-property-of-the-raised-button-class-in-flutter-doesnt-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!