Skip to content

[flutter_svg] [BUG] Caching is not working correctly. #158818

Closed

Description

@stuartmorgan-g

Imported from dnfield/flutter_svg#1074

Original report by @darkstarx on May 30, 2024

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.

Activity

  1. added
    p: flutter_svg
    package
    on Nov 13, 2024
  2. added
    P3
    on Nov 19, 2024
  3. darshankawar commented on Jul 18, 2025

    @darshankawar
    Member

    @darkstarx
    Please provide us complete minimal but reproducible code sample along with svg. Also provide the current vs expected behavior upon running the code.

  4. added
    waiting for response
    on Jul 18, 2025
  5. github-actions commented on Aug 8, 2025

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
    Thanks for your contribution.

  6. github-actions commented on Aug 22, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3p: flutter_svgpackagewaiting for response

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions