1.支持1x,2x,3x图片时
图片目录如下
images
–1.png
–x.png
–2x
—-1.png
—-x.png
–3x
—-1.png
—-x.png
images目录下默认为1倍图,2x目录下为2倍图,3x目录下为3倍图
pubspec.yaml添加配置
flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- images/
2.支持2x,3x图片时
图片目录如下
images
–1.png
–x.png
–3x
—-1.png
—-x.png
images目录下默认为2倍图,3x目录下为3倍图 pubspec.yaml添加配置
flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- images/
3.图片加载
Image.asset('images/home.png')
4.注意事项
-
没有1倍图时,无需创建2x图片目录,只需把2x图放置相应目录即可。
-
images目录下,无论默认是加载2x图片,3x图片,需要有相应图片;2x,3x,3.5x目录可以没有。不然,会出现如下错误
Image provider: AssetImage(bundle: null, name: "images/home.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#2a2d6(), name: "images/home.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════
Unable to load asset: "images/study.png".
原文始发于微信公众号(ksnowlv):Flutter本地图片管理
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/254473.html