问题
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