flutter_svg icon indicating copy to clipboard operation
flutter_svg copied to clipboard

[BUG] Caching is not working correctly.

Open darkstarx opened this issue 8 months ago • 0 comments

You use SvgCacheKey that has keyData which is SvgNetworkLoader.

  1. Implement operator== and hashCode for ColorMapper (actually there is only TestColorMapper yet).
  2. Fix calculating hashCode and comparing the SvgNetworkLoader.headers which is Map<String, String>.
  @override
  int get hashCode => Object.hash(url, headers /* HERE */, theme, colorMapper);

  @override
  bool operator ==(Object other) {
    return other is SvgNetworkLoader &&
        other.url == url &&
        other.headers == headers &&  // You NEVER get here true until these are identical maps.
        other.theme == theme &&
        other.colorMapper == colorMapper;
  }

It's hardly ever to be happend when user writes the same Map of headers on different pages, usually these are different maps with the same entries.

You have two options:

  1. Use const MapEquality().equals(headers, other.headers) in the operator== and Object.hashAll([ ...headers.keys, headers.values, ... ]) in the hashCode getter.
  2. Remove headers from hashCode and operator== since headers don't define the the source of svg data like url does.

darkstarx avatar May 30 '24 09:05 darkstarx