【问题标题】:Flutter asset image wont display properlyFlutter 资产图像无法正确显示
【发布时间】:2021-11-07 23:35:53
【问题描述】:

我想为卡片小部件添加一个图标,所以我使用了 ImageIcon 小部件,如下所示

Card(
  color: colorPalette.cultured,
  child: Padding(
    padding: const EdgeInsets.all(20.0),
    child: Row(
      children: <Widget>[
        Text(label,style: TextStyle(fontWeight: FontWeight.w600,fontSize: 15.0,fontFamily: 'Poppins'),),
        Spacer(),
        ImageIcon(AssetImage('assets/icons/call.png'),),
      ],
    ),
  ),
);

我要显示的图标是,

但显示的是,

pubspec.yaml 中的资产也正确缩进。

【问题讨论】:

  • 控制台是否有错误日志
  • 如果删除调色板会发生什么?

标签: flutter dart card flutter-assetimage


【解决方案1】:

试试下面的代码希望对你有帮助。只需根据需要更改图像

您已通过 2 种方式添加资产图片

  1. Image.assets() - 文档here
  1. AssetImage()
      Row(
             children: [
               Image(
                  image: AssetImage('assets/images/shop.png'),
                  width: 150,
                  height: 150,
                ),
                Image.asset(
                  'assets/images/cycle.png',
                  width: 150,
                  height: 150,
                ),
             ],
           ),

您的结果屏幕 ->

【讨论】:

    【解决方案2】:

    您可以使用其中任何一种来使用资产图片
    Image.asset('图片')

    Image(image: AssetImage('image')) 用于使用资产图像

    用图标实现它

    Container(
                width: 40,
                height: 40,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    color: Colors.blue),
                child: Icon(
                  Icons.call,
                  color: Colors.white,
                ),
              )
    

    【讨论】:

      猜你喜欢
      • 2019-06-17
      • 2021-01-17
      • 2021-08-13
      • 1970-01-01
      • 2020-08-01
      • 2016-09-30
      • 2021-11-23
      • 2020-08-27
      • 2021-09-26
      相关资源
      最近更新 更多