分辨率感知图像不起作用 - Flutter

Resolution aware images not working - Flutter

我正在尝试通过将每个图像转换为位图来向 google 地图添加分辨率感知图像标记:

static Future<BitmapDescriptor> makeBitmapDescriptor(String path) {
    return BitmapDescriptor.fromAssetImage(
        ImageConfiguration(), "assets/pinLocationIcons/house.png");
  }

我遵循了这种格式from flutter documentation:

.../pinLocationIcons/house.png
.../pinLocationIcons/2.0x/house.png
.../pinLocationIcons/3.0x/house.png
...etc.

它似乎在 android 和 ios 上都不起作用。 在我的 yaml 文件中,我尝试仅声明“.../image.png”,还专门声明每个 directory/file 变体。但是,它继续使用 1x 图像。

我试过这样命名文件:

.../pinLocationIcons/house.png
.../pinLocationIcons/house@2x.png
.../pinLocationIcons/house@3x.png
...etc.

这现在适用于 ios,但始终使用 1x 图像 android。 有没有我遗漏的东西可以让它同时适用于 ios 和 android?我的配置有问题吗?

如果您正在处理的项目有截止日期,我建议您手动查找资产路径。似乎您已按照 https://flutter.dev/docs/development/ui/assets-and-images

完成所有操作

经过一番调查后发现我需要在用于制作位图的图像配置中声明设备像素比。

static Future<BitmapDescriptor> makeBitmapDescriptor(
      String path, BuildContext context) {
    return BitmapDescriptor.fromAssetImage(
      ImageConfiguration(devicePixelRatio: MediaQuery.of(context).devicePixelRatio,
      path,
    );
  }