fromAssetImage static method

Future<BitmapDescriptor> fromAssetImage(
  1. ImageConfiguration configuration,
  2. String assetName, {
  3. AssetBundle? bundle,
  4. String? package,
  5. bool mipmaps = true,
})

Creates a BitmapDescriptor from an asset image.

Asset images in flutter are stored per: https://flutter.dev/docs/development/ui/assets-and-images#declaring-resolution-aware-image-assets This method takes into consideration various asset resolutions and scales the images to the right resolution depending on the dpi. Set mipmaps to false to load the exact dpi version of the image, mipmap is true by default.

Implementation

static Future<BitmapDescriptor> fromAssetImage(
  ImageConfiguration configuration,
  String assetName, {
  AssetBundle? bundle,
  String? package,
  bool mipmaps = true,
}) async {
  final double? devicePixelRatio = configuration.devicePixelRatio;
  if (!mipmaps && devicePixelRatio != null) {
    return BitmapDescriptor._(<Object>[
      _fromAssetImage,
      assetName,
      devicePixelRatio,
    ]);
  }
  final AssetImage assetImage =
      AssetImage(assetName, package: package, bundle: bundle);
  final AssetBundleImageKey assetBundleImageKey =
      await assetImage.obtainKey(configuration);
  final Size? size = configuration.size;
  return BitmapDescriptor._(<Object>[
    _fromAssetImage,
    assetBundleImageKey.name,
    assetBundleImageKey.scale,
    if (kIsWeb && size != null)
      <Object>[
        size.width,
        size.height,
      ],
  ]);
}