PopupMenuButton 颜色设置

前言:

今天在使用 flutter PopupMenuItem 的时候想设置它的选中颜色 和 点击颜色的时候,发现并没有相应的属性设置,后才测试才发现是需要 通过  Theme属性 来设置的

正确姿势:

 是要通过 Theme 属性来设置,我这只是临时用一下,如果大家是想一劳永逸,可以在 

 MaterialApp 中直接设置
Theme(
  data: Theme.of(context).copyWith(
    highlightColor: Colors.transparent,
    hoverColor: Colors.transparent,
    focusColor: Colors.transparent,
    splashColor: Colors.transparent,
  ),
  child: PopupMenuButton<int>(
    onSelected: onSelected,
    constraints: BoxConstraints(
      minWidth: 290.cale,
      maxWidth: 290.cale,
    ),
    padding: EdgeInsets.zero,
    icon: Icon(
      AppIcon.add,
      size: 46.cale,
      color: Colors.black,
    ),
    offset: Offset(0, 100.cale),
    elevation: 20.cale,
    color: AppColor.color4C4C4C,
    surfaceTintColor: Colors.transparent,
    shadowColor: Colors.black26.withOpacity(0.2),
    itemBuilder: (context) => [
      PopupMenuItem(
        value: 0,
        // mouseCursor: MaterialStateMouseCursor.clickable,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            Icon(
              AppIcon.chatGroup,
              size: 46.cale,
              color: Colors.white,
            ),
            const SizedBox(width: 15.0),
            Text(
              "发起群聊",
              style: AppTextStyle.textStyle_30_ffffff,
            ),
          ],
        ),
      ),
      PopupMenuItem(
        value: 1,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            Icon(
              AppIcon.addFriend,
              size: 46.cale,
              color: Colors.white,
            ),
            const SizedBox(width: 15.0),
            Text(
              "添加好友",
              style: AppTextStyle.textStyle_30_ffffff,
            ),
          ],
        ),
      ),
    ],
  ),
)

  设置完成之后就没有相关的点击效果了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nicepainkiller

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值