flutter_svg
flutter_svg copied to clipboard
[BUG] Caching is not working correctly.
You use SvgCacheKey
that has keyData
which is SvgNetworkLoader
.
- Implement
operator==
andhashCode
for ColorMapper (actually there is onlyTestColorMapper
yet). - Fix calculating
hashCode
and comparing theSvgNetworkLoader.headers
which isMap<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:
- Use
const MapEquality().equals(headers, other.headers)
in theoperator==
andObject.hashAll([ ...headers.keys, headers.values, ... ])
in thehashCode
getter. - Remove headers from
hashCode
andoperator==
sinceheaders
don't define the the source of svg data likeurl
does.