【问题标题】:How to resolve ImageIcon issue in flutter如何解决 Flutter 中的 ImageIcon 问题
【发布时间】:2022-11-28 11:21:56
【问题描述】:

试图在 flutter 中为图标设置图像但不起作用。那么,如何在 ListTile 中设置 ImageIcon 的路径。

这条线不起作用:

leading: ImageIcon(AssetImage('images/abt.png'), size: 25),
        GestureDetector(
            onTap: ()
            {
              Navigator.push(context, MaterialPageRoute(builder: (c)=> AboutScreen()));
            },
            child: const ListTile(
              tileColor: Colors.blue,
              leading: ImageIcon(AssetImage('images/abt.png'), size: 25),
              title: Text(
                "About",
                style: TextStyle(
                    color: Colors.black
                ),
              ),
            ),
          ),

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您可能没有在pubspec.yaml 中取消对这些行的注释

    # assets:
    #  - images/a_dot_burr.jpeg
    #  - images/a_dot_ham.jpeg
    

    【讨论】:

      【解决方案2】:

      更新pubspec.yaml 文件。

      assets:  
          - images/
          - images/abt.png  
      

      Flutter 使用位于项目根目录的 pubspec.yaml 文件来识别应用程序所需的资产。在此处阅读如何在 Flutter 中使用specify assets and images

      【讨论】:

        猜你喜欢
        • 2022-08-11
        • 2020-09-28
        • 1970-01-01
        • 2019-06-07
        • 2019-10-31
        • 1970-01-01
        • 2020-07-19
        • 2021-07-31
        • 2021-03-05
        相关资源
        最近更新 更多