dnfield / flutter_svg

SVG parsing, rendering, and widget library for Flutter
MIT License
1.66k stars 453 forks source link

Getting Unhandled Exception: FormatException: Invalid double #920

Open AppalaNaidu01 opened 1 year ago

AppalaNaidu01 commented 1 year ago

I am facing an issue while rendering the following svg: <svg width="16" height="16" fill="#F2C94C" viewBox="1 1 14 14" class="color-override"><path d="M8.3779 4.74233C8.14438 4.60607 7.85562 4.60607 7.6221 4.74233L5.37209 6.05513C5.14168 6.18957 5 6.4363 5 6.70311V9.34216C5 9.60897 5.14168 9.85573 5.37209 9.99016L7.6221 11.303C7.85562 11.4392 8.14438 11.4392 8.3779 11.303L10.6279 9.99016C10.8583 9.85573 11 9.60897 11 9.34216V6.70311C11 6.4363 10.8583 6.18957 10.6279 6.05513L8.3779 4.74233Z" mask="url(#hole-66.66666666666666)"></path><mask id="hole-66.66666666666666"><rect width="100%" height="100%" fill="white"></rect><circle r="4" cx="7.5" cy="8" fill="black" stroke="white" stroke-width="8" stroke-dasharray="calc(16.746666666666666) 25.12" transform="rotate(-90) translate(-16)"></circle></mask><path fill-rule="evenodd" clip-rule="evenodd" d="M7.24419 1.44066C7.71124 1.16822 8.28876 1.16822 8.75581 1.44066L13.2558 4.06566C13.7166 4.33448 14 4.82783 14 5.36133V10.6382C14 11.1717 13.7166 11.6651 13.2558 11.9339L8.75581 14.5589C8.28876 14.8313 7.71124 14.8313 7.24419 14.5589L2.74419 11.9339C2.28337 11.6651 2 11.1717 2 10.6382V5.36133C2 4.82783 2.28337 4.33448 2.74419 4.06566L7.24419 1.44066ZM8 2.73633L12.5 5.36133V10.6382L8 13.2632L3.5 10.6382V5.36133L8 2.73633Z"></path></svg>

Got this error:

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Invalid double
100%
#0      double.parse (dart:core-patch/double_patch.dart:112:28)
#1      parseDouble (package:vector_graphics_compiler/src/svg/numbers.dart:32:17)
#2      parseDoubleWithUnits (package:vector_graphics_compiler/src/svg/numbers.dart:82:25)
#3      SvgParser.parseDoubleWithUnits (package:vector_graphics_compiler/src/svg/parser.dart:969:20)
#4      _Paths.rect (package:vector_graphics_compiler/src/svg/parser.dart:510:34)
#5      SvgParser.addShape (package:vector_graphics_compiler/src/svg/parser.dart:886:31)
#6      SvgParser.startElement (package:vector_graphics_compiler/src/svg/parser.dart:914:12)
#7      SvgParser._parseTree (package:vector_graphics_compiler/src/svg/parser.dart:764:13)
#8      SvgParser.parse (package:vector_graphics_compiler/src/svg/parser.dart:797:5)
#9      parse (package:vector_graphics_compiler/vector_graphics_compiler.dart:76:17)
#10     encodeSvg (package:vector_graphics_compiler/vec<…>

I tried with the latest version of the library,

did I used any attribute which isn't handled by this library?

mstich-mcmservices commented 10 months ago

I'm having a similar problem - Unhandled Exception: FormatException: Invalid double 1322.856 1327.7532. I've scanned through the svg and with my limited knowledge of SVG format, I did not see anything that immediately looked erroneous.

The file in question can be pulled from:

https://drive.google.com/file/d/1HH2dBGBVcxMCVu8-y3r4sb4b0dhgxfry/view?usp=share_link

Regards.

shanelau commented 10 months ago

same error

RikClaesen commented 9 months ago

problem is cause by the '%' in rect width and height attributes. The SvgParser.parseDoubleWithUnits cannot handle the '%'

It calls numbers.parseDoubleWithUnits

eg.: double? parseDoubleWithUnits( String? rawDouble, { bool tryParse = false, }) { return numbers.parseDoubleWithUnits( rawDouble, tryParse: tryParse, theme: theme, ); }

and that one does not handle '%': double? parseDoubleWithUnits( String? rawDouble, { bool tryParse = false, required SvgTheme theme, }) { double unit = 1.0;

// 1 rem unit is equal to the root font size. // 1 em unit is equal to the current font size. // 1 ex unit is equal to the current x-height. if (rawDouble?.contains('pt') ?? false) { unit = kPointsToPixelFactor; } else if (rawDouble?.contains('rem') ?? false) { unit = theme.fontSize; } else if (rawDouble?.contains('em') ?? false) { unit = theme.fontSize; } else if (rawDouble?.contains('ex') ?? false) { unit = theme.xHeight; } final double? value = parseDouble( rawDouble, tryParse: tryParse, );

return value != null ? value * unit : null; }