Flutter中“凸起"按钮类的hoverColor属性,不会更改吗? [英] hoverColor property of the Raised button class in Flutter, doesn't change?

查看:168
本文介绍了Flutter中“凸起"按钮类的hoverColor属性,不会更改吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IOS模拟器,以下问题可能并非在所有平台上都持续存在.

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

我的印象是,在创建RaisedButton时,当光标悬停在按钮上方时,可以更改按钮的颜色.

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.

但是事实并非如此.

//创建按钮

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.

推荐答案

由于问题不是很清楚,我将假设一些事情.首先,您正在 flutter桌面网络上运行该应用.在这种情况下,代码应该可以正常工作.

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.

如果您想在点击时更改颜色,则可以 GestureDetector 包裹RaisedButton ,并使用onTap或onPanDown回调手动更改按钮的颜色.

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.

这篇关于Flutter中“凸起"按钮类的hoverColor属性,不会更改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆