dnfield / flutter_svg

SVG parsing, rendering, and widget library for Flutter
MIT License
1.64k stars 449 forks source link

Migration from the `AssetBundlePictureKey` apis #1070

Open dovahkiin98 opened 1 month ago

dovahkiin98 commented 1 month ago

I have code using classes like AssetBundlePictureKey, ExactAssetPicture, etc. But I can't seem to find any migration guide for that code?

Can someone help me?

class DynamicAssetPicture extends ExactAssetPicture {
  final int cacheHash;

  DynamicAssetPicture(
    super.assetName,
    super.decoderBuilder,
    this.cacheHash,
  );

  @override
  Future<OverrideSvgKey> obtainKey(PictureConfiguration picture) {
    return SynchronousFuture<OverrideSvgKey>(
      OverrideSvgKey(
        bundle: bundle ?? picture.bundle ?? rootBundle,
        name: keyName,
        colorFilter: colorFilter,
        cacheHash: cacheHash,
      ),
    );
  }

  @override
  bool operator ==(Object other) {
    if (other is DynamicAssetPicture) {
      return cacheHash == other.cacheHash;
    }

    return false;
  }

  @override
  int get hashCode => Object.hash(super.hashCode, cacheHash);
}

class OverrideSvgKey extends AssetBundlePictureKey {
  final int cacheHash;

  const OverrideSvgKey({
    required super.bundle,
    required super.name,
    super.colorFilter,
    required this.cacheHash,
  }) : super(
          theme: const SvgTheme(),
        );

  @override
  bool operator ==(dynamic other) => hashCode == other.hashCode;

  @override
  int get hashCode => Object.hash(super.hashCode, cacheHash);
}