美文网首页Flutter
flutter 本地图片资源找不到No file or vari

flutter 本地图片资源找不到No file or vari

作者: NullPoint3Exce | 来源:发表于2019-12-26 15:14 被阅读0次

flutter 图片资源找不到No file or variants found for asset:
先说下加载图片的流程

1.pubspec.yaml里配置图片

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  assets: // 对齐上面的依赖内容
     - images/apple.png// 该路径是相对pubspec.yaml的文件路径

/ - -images/apple.png// 该路径是相对pubspec.yaml的文件路径,相当于在pubspec.yaml目录级别下建立images文件夹。如果图片比较多,可以只配置图片的路径:如

flutter:

  uses-material-design: true
  assets: 
//代表配置图片目录的路径
     - images/ 

2.复制文件到文件夹

目录结构

3.使用

Image.asset("images/apron.png",
                    width: 100,
                    height: 100)

相关文章

网友评论

    本文标题:flutter 本地图片资源找不到No file or vari

    本文链接:https://www.haomeiwen.com/subject/zmzkoctx.html