Skip to content

[flutter_svg] Support mask-type:alpha #158734

Closed
flutter/packages
#13025

Description

@stuartmorgan-g

Imported from dnfield/flutter_svg#886

Original report by @hashirshoaeb on Mar 15, 2023

Desired Output: In mac preview and google chrome it is visible like this.
Screenshot 2023-03-15 at 6 28 28 PM

package output:
Screenshot 2023-03-15 at 6 29 11 PM

svg file:

<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="paint0_linear_2747_23934" x1="8.125" y1="5" x2="36.25" y2="26.25" gradientUnits="userSpaceOnUse">
<stop stop-color="#EEBF6D" stop-opacity="0.64"/>
<stop offset="1" stop-color="#EBB04A" stop-opacity="0.8"/>
</linearGradient>
</defs>
<circle cx="20" cy="20" r="20" fill="url(#paint0_linear_2747_23934)"/>
<mask id="mask0_2747_23934" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="12" y="12" width="20" height="16">
<path d="M30.3275 22.9176C30.3275 25.2189 28.4621 27.0843 26.1608 27.0843C25.415 27.0843 24.7141 26.8885 24.1083 26.5447C23.4667 26.1811 22.933 25.6538 22.5616 25.0166C22.1902 24.3794 21.9944 23.6552 21.9941 22.9176C21.9941 21.8476 22.3975 20.8718 23.06 20.1343C23.4503 19.6985 23.9283 19.3499 24.4627 19.1116C24.997 18.8732 25.5757 18.7503 26.1608 18.751C28.4621 18.751 30.3275 20.6164 30.3275 22.9176Z" fill="white" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M26.1641 15.001V18.751C25.579 18.7503 25.0003 18.8732 24.4659 19.1116C23.9316 19.3499 23.4536 19.6985 23.0632 20.1343C22.3757 20.8982 21.9959 21.8899 21.9974 22.9176C21.9976 23.6552 22.1934 24.3794 22.5648 25.0166C22.9362 25.6538 23.4699 26.1811 24.1116 26.5447C23.0024 26.8801 21.5299 27.0843 19.9141 27.0843C16.4624 27.0843 13.6641 26.1514 13.6641 25.001V15.001" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M26.1641 15.0003C26.1641 16.1507 23.3657 17.0837 19.9141 17.0837C16.4624 17.0837 13.6641 16.1507 13.6641 15.0003C13.6641 13.8499 16.4624 12.917 19.9141 12.917C23.3657 12.917 26.1641 13.8499 26.1641 15.0003Z" fill="white" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13.6641 21.6668C13.6641 22.8172 16.4624 23.7502 19.9141 23.7502C20.667 23.7502 21.3891 23.706 22.0574 23.6243M13.6641 18.3335C13.6641 19.4839 16.4624 20.4168 19.9141 20.4168C21.0624 20.4168 22.1386 20.3135 23.0632 20.1335" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M27.8307 22.9176H26.1641V21.251" stroke="black" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
</mask>
<g mask="url(#mask0_2747_23934)">
<path d="M12 10H32V30H12V10Z" fill="white"/>
</g>

</svg>


Comment by @dnfield on Mar 15, 2023
This is a bug in the mask optimizer.


Comment by @dnfield on Mar 15, 2023
Hm. Maybe it is not a bug in the masking optimizer, but it is a bug in mask handling...


Comment by @dnfield on Mar 15, 2023
Yeah, the mask-type is not being processed correctly in this library.


Comment by @dnfield on Mar 15, 2023
This needs a bit of thinking about how to properly apply masks that I'm not going to have time for soon. I'm open to a PR to fix this, but you can also temporarily work around it by removing the last path in your mask (which doesn't contribute to drawing in this case).


Comment by @dnfield on Mar 15, 2023

<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="paint0_linear_2747_23934" x1="8.125" y1="5" x2="36.25" y2="26.25" gradientUnits="userSpaceOnUse">
<stop stop-color="#EEBF6D" stop-opacity="0.64"/>
<stop offset="1" stop-color="#EBB04A" stop-opacity="0.8"/>
</linearGradient>
</defs>
<circle cx="20" cy="20" r="20" fill="url(#paint0_linear_2747_23934)"/>
<mask id="mask0_2747_23934" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="12" y="12" width="20" height="16">
<path d="M30.3275 22.9176C30.3275 25.2189 28.4621 27.0843 26.1608 27.0843C25.415 27.0843 24.7141 26.8885 24.1083 26.5447C23.4667 26.1811 22.933 25.6538 22.5616 25.0166C22.1902 24.3794 21.9944 23.6552 21.9941 22.9176C21.9941 21.8476 22.3975 20.8718 23.06 20.1343C23.4503 19.6985 23.9283 19.3499 24.4627 19.1116C24.997 18.8732 25.5757 18.7503 26.1608 18.751C28.4621 18.751 30.3275 20.6164 30.3275 22.9176Z" fill="white" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M26.1641 15.001V18.751C25.579 18.7503 25.0003 18.8732 24.4659 19.1116C23.9316 19.3499 23.4536 19.6985 23.0632 20.1343C22.3757 20.8982 21.9959 21.8899 21.9974 22.9176C21.9976 23.6552 22.1934 24.3794 22.5648 25.0166C22.9362 25.6538 23.4699 26.1811 24.1116 26.5447C23.0024 26.8801 21.5299 27.0843 19.9141 27.0843C16.4624 27.0843 13.6641 26.1514 13.6641 25.001V15.001" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M26.1641 15.0003C26.1641 16.1507 23.3657 17.0837 19.9141 17.0837C16.4624 17.0837 13.6641 16.1507 13.6641 15.0003C13.6641 13.8499 16.4624 12.917 19.9141 12.917C23.3657 12.917 26.1641 13.8499 26.1641 15.0003Z" fill="white" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13.6641 21.6668C13.6641 22.8172 16.4624 23.7502 19.9141 23.7502C20.667 23.7502 21.3891 23.706 22.0574 23.6243M13.6641 18.3335C13.6641 19.4839 16.4624 20.4168 19.9141 20.4168C21.0624 20.4168 22.1386 20.3135 23.0632 20.1335" stroke="white" stroke-width="1.66667" stroke-linecap="round" stroke-linejoin="round"/>
</mask>
<g mask="url(#mask0_2747_23934)">
<path d="M12 10H32V30H12V10Z" fill="white"/>
</g>

</svg>

Activity

  1. added
    p: flutter_svgThe Flutter SVG drawing packages
    packageflutter/packages repository. See also p: labels.
    on Nov 13, 2024
  2. added
    P3Issues that are less important to the Flutter project
    on Nov 20, 2024
  3. muhammadkamel commented on May 14, 2025

    @muhammadkamel
  4. darshankawar commented on Jul 18, 2025

    @darshankawar
    Member

    With original svg, the reported behavior occurs, with updated svg, it is resolved but is more of a workaround, so will keep the issue open.

  5. EArminjon commented on Feb 11, 2026

    @EArminjon
    Contributor

    The issue remain for me with this kind of SVG, i've tested on flutter web :

    <svg width="113" height="56" viewBox="0 0 113 56" fill="none" xmlns="http://www.w3.org/2000/svg">
    <mask id="mask0_6028_18552" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="9" y="0" width="95" height="56">
    <path fill-rule="evenodd" clip-rule="evenodd" d="M103.165 0H9.83203V56H103.165V28V0ZM103.165 28C103.165 17.6907 94.808 9.33333 84.4987 9.33333C74.1894 9.33333 65.832 17.6907 65.832 28C65.832 38.3093 74.1894 46.6667 84.4987 46.6667C94.808 46.6667 103.165 38.3093 103.165 28Z" fill="#000000ff"/>
    </mask>
    <g mask="url(#mask0_6028_18552)">
    <path d="M51.6004 14.5002C52.5727 14.3878 53.4362 13.8265 53.9337 12.9836C54.2682 12.3504 54.387 11.6254 54.2721 10.9186C54.176 10.3264 53.9912 9.75219 53.7237 9.21523C53.0978 7.81258 52.1066 6.6038 50.8537 5.71523C49.3002 4.57942 47.2346 4.42994 45.5337 5.33023C44.7426 5.8194 44.0979 6.51255 43.6671 7.33689C43.2972 8.04388 43.0113 8.79175 42.8154 9.56523L42.6054 10.4052L42.5004 10.8369C42.4568 11.0151 42.4023 11.1904 42.3371 11.3619C41.954 11.1001 41.7333 10.6588 41.7537 10.1952C41.7514 9.90594 41.7748 9.61703 41.8237 9.3319C41.9014 8.89122 42.0026 8.45503 42.1271 8.02523C42.1562 7.89693 42.1883 7.77155 42.2204 7.64618C42.2524 7.5208 42.2846 7.39519 42.3137 7.2669C42.5409 6.44731 42.6043 5.591 42.5004 4.7469C42.3606 3.78154 41.8012 2.9274 40.9721 2.41356C40.368 2.09273 39.6757 1.97802 39.0004 2.08689C38.4088 2.18249 37.8371 2.37568 37.3087 2.65856C35.8989 3.2839 34.6881 4.28482 33.8087 5.5519C32.7051 7.13539 32.5616 9.19751 33.4354 10.9186C33.9003 11.7104 34.5691 12.3631 35.3721 12.8086C36.1099 13.1974 36.8939 13.4914 37.7054 13.6836L38.1604 13.7886C39.0004 13.9986 39.3504 14.1036 39.4671 14.5936C39.5255 14.7275 39.5255 14.8797 39.4671 15.0136C39.2571 15.4569 38.4054 15.4802 37.6937 15.3519C37.2504 15.2702 36.8304 15.1652 36.4104 15.0486L35.6637 14.8619C34.8538 14.6258 34.0041 14.5583 33.1671 14.6636C32.1969 14.8071 31.3414 15.3761 30.8337 16.2152C30.5183 16.8546 30.4122 17.5771 30.5304 18.2802C30.6353 18.8702 30.8198 19.4432 31.0787 19.9836C31.699 21.3863 32.6865 22.5956 33.9371 23.4836C35.4946 24.6086 37.5538 24.7576 39.2571 23.8686C40.0473 23.3819 40.6888 22.6878 41.1121 21.8619C41.5177 21.0443 41.8157 20.1777 41.9987 19.2836L42.0804 18.9102L42.0835 18.8961C42.1991 18.3639 42.3166 17.8235 42.6404 17.6269C42.8019 17.5458 42.9922 17.5458 43.1537 17.6269C43.4967 17.8576 43.692 18.2526 43.6671 18.6652C43.6794 18.9457 43.6677 19.2267 43.6321 19.5052C43.5754 19.8641 43.4882 20.2153 43.4013 20.5651C43.3808 20.6474 43.3604 20.7297 43.3404 20.8119C43.3196 20.8847 43.2937 20.9585 43.2675 21.033C43.2055 21.2094 43.1421 21.3898 43.1421 21.5702C42.9147 22.3898 42.8512 23.2461 42.9554 24.0902C43.0952 25.0556 43.6546 25.9097 44.4837 26.4236C44.9251 26.6603 45.4179 26.7845 45.9187 26.7852C46.0933 26.8025 46.2692 26.8025 46.4437 26.7852C47.0398 26.6836 47.6176 26.4949 48.1587 26.2252C49.5715 25.6046 50.7835 24.6027 51.6587 23.3319C52.8084 21.7467 52.9707 19.6502 52.0787 17.9069C51.6081 17.1144 50.9305 16.4651 50.1187 16.0286C49.1603 15.5391 48.1399 15.182 47.0854 14.9669L46.1871 14.7452C45.9351 14.588 45.7391 14.3553 45.6271 14.0802C45.6381 14.0121 45.6662 13.9479 45.7087 13.8936C45.8021 13.7536 46.1754 13.7536 46.3271 13.7536C46.6091 13.7518 46.8906 13.7791 47.1671 13.8352C47.5609 13.9068 47.9504 14.0003 48.3337 14.1152L49.1154 14.3136C49.9225 14.5438 50.768 14.6073 51.6004 14.5002Z" fill="#000000ff"/>
    </g>
    <g clip-path="url(#clip0_6028_18552)">
    <path fill-rule="evenodd" clip-rule="evenodd" d="M91.5882 19.5315C91.2844 19.2278 90.792 19.2278 90.4882 19.5315L84.6577 25.3621L78.6694 19.3739C78.3657 19.0701 77.8732 19.0701 77.5695 19.3739L76.0296 20.9138C75.7258 21.2175 75.7258 21.71 76.0296 22.0137L82.0178 28.002L76.189 33.8308C75.8852 34.1345 75.8852 34.627 76.189 34.9307L77.7289 36.4707C78.0326 36.7744 78.5251 36.7744 78.8288 36.4707L84.6577 30.6418L90.3288 36.313C90.6326 36.6167 91.125 36.6167 91.4288 36.313L92.9687 34.7731C93.2725 34.4693 93.2725 33.9769 92.9687 33.6731L87.2975 28.002L93.1281 22.1714C93.4318 21.8677 93.4318 21.3752 93.1281 21.0714L91.5882 19.5315Z" fill="#000000ff"/>
    </g>
    <defs>
    <clipPath id="clip0_6028_18552">
    <rect width="28" height="28" fill="#000000ff" transform="translate(70.5 14)" x="0" y="0"/>
    </clipPath>
    </defs>
    </svg>

    Flutter display :

    Image

    We should see :

    Image

    https://editsvgcode.com/

    Flutter doctor -v
    [✓] Flutter (Channel stable, 3.38.6, on macOS 26.2 25C56 darwin-arm64, locale fr-FR) [1 280ms]
        • Flutter version 3.38.6 on channel stable at /Users/earminjon/fvm/versions/3.38.6
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 8b87286849 (5 weeks ago), 2026-01-08 10:49:17 -0800
        • Engine revision 78fc3012e4
        • Dart version 3.10.7
        • DevTools version 2.51.1
        • Pub download mirror https://artifactory.dt.renault.com/artifactory/api/pub/pub-ccx-irn76318
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
          cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [1 981ms]
        • Android SDK at /Users/earminjon/Library/Android/sdk
        • Emulator version 36.3.10.0 (build_id 14472402) (CL:N/A)
        • Platform android-36, build-tools 36.1.0
        • ANDROID_HOME = /Users/earminjon/Library/Android/sdk
        • Java binary at: /Users/earminjon/Library/Java/JavaVirtualMachines/corretto-17.0.14/Contents/Home/bin/java
          This JDK is specified in your Flutter configuration.
          To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment Corretto-17.0.14.7.1 (build 17.0.14+7-LTS)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.2) [1 913ms]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 17C52
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [6ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Network resources [155ms]
        • All expected network resources are available.
  6. github-actions commented on Oct 26, 2026

    @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 Oct 26, 2026
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

    P3Issues that are less important to the Flutter projectfound in release: 3.32Found to occur in 3.32has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_svgThe Flutter SVG drawing packagespackageflutter/packages repository. See also p: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions