yang-f / flutter_svg_provider

Use svg as image provider.
https://pub.dev/packages/flutter_svg_provider
Apache License 2.0
47 stars 72 forks source link

Color should be part of SvgImageKey #42

Open erickok opened 1 year ago

erickok commented 1 year ago

The same image is provided by the library when you change only the color property. This is because color is incorrectly not part of the == (equals) method of SvgImageKey.

https://github.com/yang-f/flutter_svg_provider/blob/fd32f3c80c7756a8a26520f063ae54f4139c3dc2/lib/flutter_svg_provider.dart#L188

    return other is SvgImageKey &&
        other.path == path &&
        other.pixelWidth == pixelWidth &&
        other.pixelHeight == pixelHeight &&
        other.scale == scale &&
        other.source == source &&
        other.svgGetter == svgGetter;

This leads to bugs such as the provider not providing an updated image when your theme updates (such as when enabling dark/light mode) and your image only changes the svg's applied color. For example:

        image: DecorationImage(
          image: SvgProvider(
            "assets/somewhere/in/my/app/some_grpahic.svg",
            color: inDarkTheme ? Colors.grey.shade800 : Colors.grey.shade200,
          ),
        ),