Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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.

like image 397
rb2030 Avatar asked Sep 19 '19 13:09

rb2030


People also ask

How do you change the elevated button on Flutter?

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.

Is Raised button deprecated in Flutter?

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.

What is hoverColor 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.


1 Answers

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.

like image 56
Ronak Punase Avatar answered Nov 15 '22 08:11

Ronak Punase