admin管理员组文章数量:1023230
I'm trying to change or quit the default color when hovering a widget in Flutter web, in specific with showMenu function like this: `
items: items.map(
(item) {
return PopupMenuItem<String>(
value: item,
child: SizedBox(
width: widthItems,
child: _HoverableMenuItem(
text: item,
),
),
);
},
).toList(),`
and i tried to use MouseRegion to change the item color, like this
MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: Container(
color: _isHovered ? Colors.blue.withOpacity(0.1) : Colors.transparent,
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 0,
),
child: Text(
widget.text,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
),
)
it works in some way, but there is still the default grey color behind when hovering , and i want to know if there is a way to hide it or just change it without quit completely the hover styles in my app
I'm trying to change or quit the default color when hovering a widget in Flutter web, in specific with showMenu function like this: `
items: items.map(
(item) {
return PopupMenuItem<String>(
value: item,
child: SizedBox(
width: widthItems,
child: _HoverableMenuItem(
text: item,
),
),
);
},
).toList(),`
and i tried to use MouseRegion to change the item color, like this
MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: Container(
color: _isHovered ? Colors.blue.withOpacity(0.1) : Colors.transparent,
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 0,
),
child: Text(
widget.text,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
),
)
it works in some way, but there is still the default grey color behind when hovering , and i want to know if there is a way to hide it or just change it without quit completely the hover styles in my app
Share Improve this question asked Nov 18, 2024 at 20:18 Erick GalvánErick Galván 387 bronze badges 1- Anything with a Color-type parameter can use a WidgetStateColor which can be programmed to automatically respond to hover state. You don't need the mouse stuff... it'll be automatic. – Randal Schwartz Commented Nov 18, 2024 at 23:02
1 Answer
Reset to default 0Do you think that something like it could be work for you?
Center(
child: Material(
color: Colors.transparent,
child: InkWell(
onHover: (val) {
setState(() {
colorHover = val ? Colors.red : Colors.yellow;
});
},
onTap: () {},
child: AnimatedContainer(
color: colorHover,
height: 400,
width: 400,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn,
child: Container(
height: 400,
width: 400,
),
),
),
)),
Need to declare Color colorHover = Colors.yellow;
More here: https://api.flutter.dev/flutter/material/InkWell-class.html
I'm trying to change or quit the default color when hovering a widget in Flutter web, in specific with showMenu function like this: `
items: items.map(
(item) {
return PopupMenuItem<String>(
value: item,
child: SizedBox(
width: widthItems,
child: _HoverableMenuItem(
text: item,
),
),
);
},
).toList(),`
and i tried to use MouseRegion to change the item color, like this
MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: Container(
color: _isHovered ? Colors.blue.withOpacity(0.1) : Colors.transparent,
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 0,
),
child: Text(
widget.text,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
),
)
it works in some way, but there is still the default grey color behind when hovering , and i want to know if there is a way to hide it or just change it without quit completely the hover styles in my app
I'm trying to change or quit the default color when hovering a widget in Flutter web, in specific with showMenu function like this: `
items: items.map(
(item) {
return PopupMenuItem<String>(
value: item,
child: SizedBox(
width: widthItems,
child: _HoverableMenuItem(
text: item,
),
),
);
},
).toList(),`
and i tried to use MouseRegion to change the item color, like this
MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: Container(
color: _isHovered ? Colors.blue.withOpacity(0.1) : Colors.transparent,
padding: const EdgeInsets.symmetric(
vertical: 15,
horizontal: 0,
),
child: Text(
widget.text,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
),
)
it works in some way, but there is still the default grey color behind when hovering , and i want to know if there is a way to hide it or just change it without quit completely the hover styles in my app
Share Improve this question asked Nov 18, 2024 at 20:18 Erick GalvánErick Galván 387 bronze badges 1- Anything with a Color-type parameter can use a WidgetStateColor which can be programmed to automatically respond to hover state. You don't need the mouse stuff... it'll be automatic. – Randal Schwartz Commented Nov 18, 2024 at 23:02
1 Answer
Reset to default 0Do you think that something like it could be work for you?
Center(
child: Material(
color: Colors.transparent,
child: InkWell(
onHover: (val) {
setState(() {
colorHover = val ? Colors.red : Colors.yellow;
});
},
onTap: () {},
child: AnimatedContainer(
color: colorHover,
height: 400,
width: 400,
duration: Duration(milliseconds: 200),
curve: Curves.easeIn,
child: Container(
height: 400,
width: 400,
),
),
),
)),
Need to declare Color colorHover = Colors.yellow;
More here: https://api.flutter.dev/flutter/material/InkWell-class.html
本文标签: Can I change default hover color for only one widget in FlutterStack Overflow
版权声明:本文标题:Can I change default hover color for only one widget in Flutter? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745596432a2158198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论