fromScaledAsset static method

Future<ArcGISImage> fromScaledAsset(
  1. String assetKey, {
  2. double devicePixelScale = 1.0,
})

For use with resolution-aware image assets, retrieves an ArcGISImage from the rootBundle under the key assetKey, matching the devicePixelScale.

Implementation

static Future<ArcGISImage> fromScaledAsset(
  String assetKey, {
  double devicePixelScale = 1.0,
}) async {
  const scales = [1.0, 1.5, 2.0, 3.0, 4.0];

  // Set to largest scale for if devicePixelScale is greater than highest scale.
  var imgScale = scales.last;

  for (final scale in scales) {
    if (devicePixelScale <= scale) {
      imgScale = scale;
      break;
    }
  }

  // Modify the asset key string to include the scale
  var scaledAssetKey = assetKey;
  if (imgScale != 1.0) {
    final assetKeyComponents = assetKey.split('/');
    assetKeyComponents.insert(assetKeyComponents.length - 1, '${imgScale}x');
    scaledAssetKey = assetKeyComponents.join('/');
  }

  return fromAsset(scaledAssetKey);
}