我累了半天,现在改变foregroundColor和删除backgroundColor的按钮悬停,我的代码:
final ThemeData lightTheme = ThemeData(
menuButtonTheme: MenuButtonThemeData(style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
print("this never printed!!!");
return Colors.red;
}
return Colors.blue;
},
),
))
);
class AppScreen extends StatelessWidget {
final Widget? child;
AppScreen({Key? key, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AppBar Demo'),
actions: <Widget>[
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem<int>(
value: 0,
child: Text("My Emails"),
),
PopupMenuItem<int>(
value: 1, child: Text("Sign Out"),
),
],
onSelected: (item) {},
child: TextButton.icon(
style: Theme.of(context).menuButtonTheme.style,
icon: Icon(Icons.account_circle),
label: Text(
'Maya Amor'
), onPressed: null,
),
)
],
),
body: child,
);
}
}
字符串
按钮的颜色永远不会改变,当我悬停在按钮上时,我可以看到按钮的背景以一种我无法改变的方式发生变化,无论我做了什么。
1条答案
按热度按时间khbbv19g1#
要在悬停时更改
PopupMenuItem
的color
,可以使用MouseRegion
小部件在
onHover
和onExit
函数中,可以实现更改color
的逻辑widget的
hover color
通常由app的theme
控制。如果你想为特定的widget禁用hover color
,你可以将它 Package 在Theme
widget中,并在ThemeData
中将hoverColor
设置为Colors.transparent
。字符串
验证码:
型
输出值:
的数据