[英]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.