简体   繁体   English

如何使用 flutter 在 hover 上显示小部件?

[英]How to show a widget on hover with flutter?

is there a way to make a widget (ex. a button) visible only on hover?有没有办法让小部件(例如按钮)仅在 hover 上可见? I want to make a way to show the edit button on the image just when image is hovered.我想想办法在图像悬停时在图像上显示编辑按钮。

            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,
            ),
                ),
              ],
            ),

Thank you.谢谢你。

place this code inside your StatefulWidget widget:将此代码放在您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM