经过几个小时的搜索,根据官方文档 https://flutter.dev/docs/development/ui/assets-and-images#resolution-aware,颤振取决于设备像素比这是:
Device Pixel Ratio (DPR) is the relationship between physical
hardware-based pixels and Device-Independent Pixels which are an abstraction.
对于安卓:
Denisty Pixel Ratio
mdpi 1.0x
hdpi 1.5x
xhdpi 2.0x
xxhdpi 3.0x
xxxhdpi 4.0x
For Ios:
对于颤动:
.../image.png
.../Mx/image.png
.../Nx/image.png
...etc.
其中 M 和 N 是数字标识符,对应于其中包含的图像的标称分辨率。
换句话说,它们指定图像所需的设备像素比。
假定主要资产对应于 1.0 的分辨率。例如,考虑图像的以下资源布局
所以这取决于你有多少分辨率来创建你的assets文件夹的不同子目录,所以我的建议是创建以下子目录文件夹来覆盖所有DPR:
.../image.png ---> default for android mdpi(1.0x) and ios @1x
.../1.5x/image.png ---> default for android hdpi(1.5x)
.../2.0x/image.png ---> default for android xhdpi(2.0x) and ios @2x
.../3.0x/image.png ---> default for android xxhdpi(3.0x) and ios @3x
.../4.0x/image.png ---> default for android xxxhdpi(4.0x)
在颤振项目中:
在 pubspec.yaml 中只需添加默认图像路径:
assets:
- assets/images/image.png
如果有人需要使用 SVG,只需检查此package https://pub.dev/packages/flutter_svg/example:
SvgPicture.asset(assetName)