fromAssetImage 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 {
  if (!mipmaps && configuration.devicePixelRatio != null) {
    return BitmapDescriptor._(<dynamic>[
      'fromAssetImage',
      assetName,
      configuration.devicePixelRatio,
    ]);
  }
  final AssetImage assetImage =
      AssetImage(assetName, package: package, bundle: bundle);
  final AssetBundleImageKey assetBundleImageKey =
      await assetImage.obtainKey(configuration);
  return BitmapDescriptor._(<dynamic>[
    'fromAssetImage',
    assetBundleImageKey.name,
    assetBundleImageKey.scale,
    if (kIsWeb && configuration?.size != null)
      [
        configuration.size.width,
        configuration.size.height,
      ],
  ]);
}