前言:
今天在使用 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, ), ], ), ), ], ), )
设置完成之后就没有相关的点击效果了