Flutter 图标显示为矩形

如何解决Flutter 图标显示为矩形

我正在使用从 fluttericons.com 生成自定义颤动图标。但这里的问题是我的图标没有出现。它在预览中显示带有删除符号的矩形框,如下所示。 (参考下图)

enter image description here

这是我的自定义图标按钮小部件的代码片段。

xticklabels

如果想制作一个悬停图标按钮。我尝试使用 IconButton 并且失败了..有什么办法可以做到..或 请任何人帮助我摆脱这种情况。

解决方法

据我所知移动设备上没有悬停动作,所以我更改了图标按钮的初始颜色。

我为自己制作了一个 CustomIcon 按钮类,希望这可以帮助您:

class IconButton extends StatelessWidget {
  String text = 'demoText';
  Color hoverColor;
  String icon ='';
  GestureTapCallback onTap;

  IconButton(
      {Key key,this.text,this.icon,this.onTap,this.hoverColor = Colors.grey})
      : assert(text != null),assert(icon != null),super(key: key);

  @override
  Widget build(BuildContext context) {
    double height = MediaQuery.of(context).size.height;
    double width = MediaQuery.of(context).size.width;
    return Container(
      height: height * .155,width: width * .44,decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),border: Border.all(width: .2,color: Colors.green),color: Color(0xffFFFFFF),boxShadow: [
            BoxShadow(
                color: Colors.grey[350],blurRadius: 3,offset: Offset(2.5,4))
          ]),child: Material(
        clipBehavior: Clip.antiAlias,shape:
            RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),// <------------------------- Inner Material
        type: MaterialType.transparency,elevation: 6.0,color: Colors.transparent,shadowColor: Colors.grey[50],child: InkWell(
          //<------------------------- InkWell
          splashColor: hoverColor,onTap: onTap,child: Container(
            padding: EdgeInsets.all(16.0),child: Row(
              mainAxisSize: MainAxisSize.max,mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
                Column(
                  children: <Widget>[
                    Container(
                    height: height * .07,width: width * .15,child: CachedNetworkImage(
                        imageUrl: icon,progressIndicatorBuilder:
                            (context,url,downloadProgress) =>
                                CircularProgressIndicator(
                                    value: downloadProgress.progress),errorWidget: (context,error) => 
                        Icon(Icons.error),),//please add as you 
                      need:Image.asset,SvgPicture.asset etc
                    SizedBox(
                      height: height * .009,Text(
                      text,style: TextStyle(
                          fontSize: 12.0,fontWeight: FontWeight.w600,color: Color(0xff434343)),)
                  ],)
              ],);
  }
}

您可以根据需要进行修改。前通话:

    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,children: [
                IconButton(
                  hoverColor: Colors.greenAccent,//Change hover color as you need
                  text: "Google",icon:"any image url",onTap: () {},],);
      }
    }

告诉我它是否对您有帮助,或者您遇到了困难。

用于显示网络图像的包:https://pub.dev/packages/cached_network_image

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?