美文网首页
自动管理flutter里面pubspec.yaml文件的图片资源

自动管理flutter里面pubspec.yaml文件的图片资源

作者: I_YoYo | 来源:发表于2021-06-21 09:41 被阅读0次
pubspec.yaml里面的图片资源路径需要手动写入,就像这样。 pubspec.yaml.png

但是一次性添加多张图片时候很容易写错、写漏。所以可以通过脚本程序来帮忙。
fluter_img.sh脚本文件内容如下:

function echo_name(){ 
 for file in `ls $1` 
 do 
if [ -d $1"/"$file  ]; 
then
  echo "#"$1"/"$file 
else
  echo "    - "$1"/"$file 
fi

  if [ -d $1"/"$file ] 
  then 
   echo_name $1"/"$file 
   fi 
 done 
} 
  
echo_name $1
使用方式:

1,把脚本文件命名为fluter_img.sh ,放到需要遍历的图片资源的目录的同一层。
2,cd到images(图片资源目录的上层目录)。
3,运行脚本并携带参数 fluter_img.sh images (images是存放图片资源的目录,脚本会遍历这个目录),并输出图片名称路径,直接拷贝粘贴到.yaml文件即可。

运行脚本.png
方式二(推荐),通过声明图片资源所在目录,系统也能寻找到图片,比起上面方式更简洁。
assets:
    - images/2.0x/
    - images/business/portrayal/
    - images/common/
    - images/menu/
    - images/placeholder/

有什么错误欢迎批评指正 。

相关文章

网友评论

      本文标题:自动管理flutter里面pubspec.yaml文件的图片资源

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