Skip to content

[flutter_svg] FormatException: Invalid double when x or y values contain a List<double> #165490

Closed
flutter/packages
#13287

Description

@hanskokx

Steps to reproduce

  1. Create an SVG with a List<double> for the x or y value in, for example, the <text> field
  2. Open the SVG in any program that renders SVGs (e.g., macOS Preview.app) to verify the SVG displays correctly
  3. Validate the SVG against vector_graphics_compiler

Expected results

The SVG should be validated correctly.

Actual results

SVGs containing a List<double> for x or y properties fail to validate.

Code sample

Code sample

SVG:

<?xml version="1.0" encoding="utf-8" ?>
<svg
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  width="1024"
  height="1024"
>
  <text
    transform="translate(415.282 362.619)"
    font-size="9.0427618"
    font-family="Arial"
    x="0 4.8639984 10.014633 14.741928 19.654434 22.608994 24.805069 29.955704 34.943176 37.18335 42.333984 45.473755 47.713928 52.785187 57.697693"
    y="8"
  >
    Hello world
  </text>
</svg>

Working "fix":

svgImageString
..replaceAllMapped(
  RegExp(r'(<text[^>]*\bx=")(\d+(?:\.\d+)?)[^"]*"'),
  (Match m) => '${m[1]}${m[2]}"',
)
..replaceAllMapped(
  RegExp(r'(<text[^>]*\by=")(\d+(?:\.\d+)?)[^"]*"'),
  (Match m) => '${m[1]}${m[2]}"',
);

Screenshots or Video

No response

Logs

Logs
dart run vector_graphics_compiler -i test.svg -o temp.svg --no-optimize-masks --no-optimize-clips --no-optimize-overdraw --no-tessellate
Resolving dependencies in `./`...
Downloading packages...
Got dependencies in `./`.
Building package executable...
Built vector_graphics_compiler:vector_graphics_compiler.
XXXXXXXXXXX test.svg XXXXXXXXXXXXX
FormatException: Invalid double
0, 4.8639984, 10.014633, 14.741928, 19.654434, 22.608994, 24.805069, 29.955...
#0      double.parse (dart:core-patch/double_patch.dart:112:7)
#1      parseDouble (package:vector_graphics_compiler/src/svg/numbers.dart:32:17)
#2      DoubleOrPercentage.fromString (package:vector_graphics_compiler/src/svg/parser.dart:2160:33)
#3      SvgParser._createSvgAttributes (package:vector_graphics_compiler/src/svg/parser.dart:1673:31)
#4      SvgParser._readSubtree (package:vector_graphics_compiler/src/svg/parser.dart:693:30)
#5      _SyncStarIterator.moveNext (dart:async-patch/async_patch.dart:595:13)
#6      SvgParser._parseTree (package:vector_graphics_compiler/src/svg/parser.dart:770:34)
#7      SvgParser.parse (package:vector_graphics_compiler/src/svg/parser.dart:805:5)
#8      parse (package:vector_graphics_compiler/vector_graphics_compiler.dart:76:17)
#9      encodeSvg (package:vector_graphics_compiler/vector_graphics_compiler.dart:143:5)
#10     IsolateProcessor._process.<anonymous closure> (file:///Users/hans/.puro/shared/pub_cache/hosted/pub.dev/vector_graphics_compiler-1.1.16/bin/util/isolate_processor.dart:111:33)
#11     _RemoteRunner._run (dart:isolate:1118:47)
#12     _RemoteRunner._remoteExecute (dart:isolate:1112:12)
#13     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:318:17)
#14     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)

Some targets failed.

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.2, on macOS 15.3.2 24D81 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.3)
[✓] VS Code (version 1.98.2)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

Activity

  1. maheshj01 commented on Mar 20, 2025

    @maheshj01
    Member

    Reproducible using latest version of vector_graphics_compiler: ^1.1.16

    logs
    (.venv) mahesh@MacBook-Pro-10 sample_app % which dart
    /Users/mahesh/Development/flutter_master/bin/dart
    (.venv) mahesh@MacBook-Pro-10 sample_app % dart run vector_graphics_compiler -i test.svg -o temp.svg --no-optimize-masks --no-optimize-clips --no-optimize-overdraw --no-tessellate
    Resolving dependencies in `/Users/mahesh/Development/Triage/sample_app`... 
    Downloading packages... 
    Got dependencies in `/Users/mahesh/Development/Triage/sample_app`.
    Building package executable... 
    Built vector_graphics_compiler:vector_graphics_compiler.
    XXXXXXXXXXX test.svg XXXXXXXXXXXXX
    FormatException: Invalid double
    0 4.8639984 10.014633 14.741928 19.654434 22.608994 24.805069 29.955704 34....
    #0      double.parse (dart:core-patch/double_patch.dart:112:7)
    #1      parseDouble (package:vector_graphics_compiler/src/svg/numbers.dart:32:17)
    #2      DoubleOrPercentage.fromString (package:vector_graphics_compiler/src/svg/parser.dart:2160:33)
    #3      SvgParser._createSvgAttributes (package:vector_graphics_compiler/src/svg/parser.dart:1673:31)
    #4      SvgParser._readSubtree (package:vector_graphics_compiler/src/svg/parser.dart:693:30)
    #5      _SyncStarIterator.moveNext (dart:async-patch/async_patch.dart:595:13)
    #6      SvgParser._parseTree (package:vector_graphics_compiler/src/svg/parser.dart:770:34)
    #7      SvgParser.parse (package:vector_graphics_compiler/src/svg/parser.dart:805:5)
    #8      parse (package:vector_graphics_compiler/vector_graphics_compiler.dart:76:17)
    #9      encodeSvg (package:vector_graphics_compiler/vector_graphics_compiler.dart:143:5)
    #10     IsolateProcessor._process.<anonymous closure> (file:///Users/mahesh/.pub-cache/hosted/pub.dev/vector_graphics_compiler-1.1.16/bin/util/isolate_processor.dart:111:33)
    #11     _RemoteRunner._run (dart:isolate:1116:47)
    #12     _RemoteRunner._remoteExecute (dart:isolate:1110:12)
    #13     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:318:17)
    #14     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)
    
    Some targets failed.
    flutter doctor -v

    master

    ✓] Flutter (Channel master, 3.31.0-1.0.pre.345, on macOS 15.1.1 24B2091 darwin-arm64, locale en-US) [2.6s]
        • Flutter version 3.31.0-1.0.pre.345 on channel master at /Users/mahesh/Development/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 9ce60b743d (2 hours ago), 2025-03-31 23:50:27 +0300
        • Engine revision 9ce60b743d
        • Dart version 3.8.0 (build 3.8.0-245.0.dev)
        • DevTools version 2.45.0-dev.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.1s]
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-35, build-tools 35.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.0) [1,745ms]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 16A242d
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [147ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.3) [146ms]
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1) [144ms]
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.96.2) [19ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.102.0
    
    [✓] Connected device (2 available) [7.0s]
        • macOS (desktop) • macos  • darwin-arm64   • macOS 15.1.1 24B2091 darwin-arm64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 131.0.6778.265
    
    [✓] Network resources [688ms]
        • All expected network resources are available.
    
    • No issues found!

    stable

    [✓] Flutter (Channel stable, 3.29.2, on macOS 15.1.1 24B2091 darwin-arm64, locale en-US) [822ms]
        • Flutter version 3.29.2 on channel stable at /Users/mahesh/Development/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision c236373904 (2 weeks ago), 2025-03-13 16:17:06 -0400
        • Engine revision 18b71d647a
        • Dart version 3.7.2
        • DevTools version 2.42.3
    [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3.2s]
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-35, build-tools 35.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.0) [3.1s]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 16A242d
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [136ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2024.3) [135ms]
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1) [134ms]
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.96.2) [18ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.102.0
    
    [✓] Connected device (4 available) [6.7s]
        • iPad Pro 11-inch (M4) (mobile)  • A97192B5-5CFD-4164-BF2A-A6E2972614FF • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-0
          (simulator)
        • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.1.1 24B2091 darwin-arm64
        • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.1.1 24B2091 darwin-arm64
        • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 131.0.6778.265
    
    [✓] Network resources [294ms]
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  2. added
    packageflutter/packages repository. See also p: labels.
    p: flutter_svgThe Flutter SVG drawing packages
    and removed
    in triagePresently being triaged by the triage team
    on Mar 20, 2025
  3. mackings commented on Oct 16, 2026

    @mackings

    I'd like to fix this. The compiler parses x/y as a single number, so a list throws. I'll use the first value in the list, since per-character positioning isn't supported.

  4. github-actions commented on Nov 10, 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.

  5. locked as resolved and limited conversation to collaborators on Nov 10, 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

    found in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_svgThe Flutter SVG drawing packagesp: vector_graphicsThe vector_graphics package setpackageflutter/packages repository. See also p: labels.team-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions