[英]How to show a widget on hover with flutter?
有没有办法让小部件(例如按钮)仅在 hover 上可见? 我想想办法在图像悬停时在图像上显示编辑按钮。
Stack(
children: <Widget>[
Image.asset(
'assets/profileimg/empty.jpg',
width: 110.0,
height: 110.0,
),
Positioned(
bottom: -2,
left: 5,
child: RaisedButton(
child: Text('Edit...'),
onPressed: null,
),
),
],
),
谢谢你。
将此代码放在您的StatefulWidget
小部件中:
bool showEditButton = false;
Widget build(BuildContext context){
return Stack(
children: <Widget>[
InkWell(
onTap: ()=>setState(()=>showEditButton = true),
child: Image.asset(
'assets/profileimg/empty.jpg',
width: 110.0,
height: 110.0,
),
),
if(showEditButton)
Positioned(
bottom: -2,
left: 5,
child: RaisedButton(
child: Text('Edit...'),
onPressed: null,
),
),
],
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.