fromAssetImage static method

  1. @Deprecated('Switch to using `asset` method, AssetMapBitmap or AssetMapBitmap.create instead')
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.cn/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

@Deprecated(
    'Switch to using `asset` method, AssetMapBitmap or AssetMapBitmap.create instead')
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,
      ],
  ]);
}