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.
You can custom the shape of an elevated button by using the shape parameter of the styleFrom method. Example: ElevatedButton( onPressed: () {}, child: const Text('Kindacode.com'), style: ElevatedButton.
This class is deprecated, please use ElevatedButton instead. The original classes will eventually be removed, please migrate code that uses them. There's a detailed migration guide for the new button and button theme classes in flutter.
hoverColor. The color of the ink response when a pointer is hovering over it. If this property is null then the hover color of the theme, ThemeData.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With