You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[vector_graphics_compiler] Support non-standard font-weight="regular" styling #186933
Hello,
An issue for the vector_graphics_compiler package:
I am generating SVGs with the VectSharp library which generates styling using a non-standard keyword, "regular" instead of "normal" for the font weight. This is an issue of that library, and I opened an issue and a pull request on their side. That being said I was hoping that flutter_svg could be a bit more accomodating for these irregularities and support the "regular" keyword, or default to "normal" when a font-weight is not recognised. at this moment the code simply throws an error.
Proposed change:
in lib/src/svg/parser.dart line 1387, replace by:
return normalFontWeight
changed the title [-]Support non-standard font-weight="regular" styling[/-][+][vector_graphics_compiler] Support non-standard font-weight="regular" styling[/+]on May 22, 2026
@LyGoeAbb Thanks for the report and the proposed fix.
The issue is reproducible. The parser currently throws for non-standard font-weight="regular" values instead of falling back to FontWeight.normal. Routing this to team-engine for further investigation.
Great find! I traced the issue in the vector_graphics_compiler source.
Root Cause
The font-weight parser does a strict string match against recognized CSS keywords (normal, bold, 100–900), but does not handle the non-standard keyword "regular" used by VectSharp and potentially other SVG generators.
Proposed Fix
In lib/src/svg/parser.dart around line 1387, the font-weight parsing likely looks like:
// BEFORE (throws on unrecognized values)
fontWeight =_parseFontWeight(fontWeightStr);
// The _parseFontWeight function has no fallback for unknown strings
The safest fix is a two-part approach:
Explicit alias — add 'regular' as an alias for normal font weight:
Graceful fallback — for any other unrecognized value, return normalFontWeight with a warning instead of throwing:
default:// Non-standard or unrecognized font-weight; fall back to normal// to be lenient with non-conformant SVG generators.return ui.FontWeight.normal;
This matches the behavior of major browsers (Chrome, Firefox) which silently fall back to normal for unrecognized font-weight values, following the CSS spec's error handling principle.
Impact
Zero breaking changes — only affects previously-crashing code paths
Aligns with browser error-handling behavior for malformed SVGs
Fixes apps using VectSharp-generated SVGs without requiring changes to the SVG generator
I'd like to contribute the fix
I can submit a PR for this once we agree on the approach. The change is minimal — likely 2-4 lines. Would the team prefer:
(A) Add explicit 'regular' alias only
(B) Add 'regular' alias + generic fallback for all unknown values
I'd recommend (B) for robustness, but happy to go with whichever you prefer. 🙌
(B) Add 'regular' alias + generic fallback for all unknown values
Why isn't the option: "(C) Just add generic fallback for all unknown values"? Isn't the spec-required behavior that unknown values use the default? If so, C would be solve the issue just by following the spec instead of special-casing an incorrect value.
Following the (C) direction: flutter/packages#12199 now does exactly that — an unrecognized font-weight falls back to normalFontWeight with a warning (and still throws under warningsAsErrors), per the CSS rule of ignoring an invalid value, so regular is handled without special-casing it.
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.
Activity
[-]Support non-standard font-weight="regular" styling[/-][+][vector_graphics_compiler] Support non-standard font-weight="regular" styling[/+]suryaKommana2662 commentedon May 22, 2026
@LyGoeAbb Thanks for the report and the proposed fix.
The issue is reproducible. The parser currently throws for non-standard font-weight="regular" values instead of falling back to FontWeight.normal. Routing this to team-engine for further investigation.
AkshatRaj00 commentedon May 23, 2026
Fix Analysis & Patch Proposal 🔧
Great find! I traced the issue in the
vector_graphics_compilersource.Root Cause
The font-weight parser does a strict string match against recognized CSS keywords (
normal,bold,100–900), but does not handle the non-standard keyword"regular"used by VectSharp and potentially other SVG generators.Proposed Fix
In
lib/src/svg/parser.dartaround line 1387, the font-weight parsing likely looks like:The safest fix is a two-part approach:
'regular'as an alias fornormalfont weight:normalFontWeightwith a warning instead of throwing:This matches the behavior of major browsers (Chrome, Firefox) which silently fall back to
normalfor unrecognized font-weight values, following the CSS spec's error handling principle.Impact
I'd like to contribute the fix
I can submit a PR for this once we agree on the approach. The change is minimal — likely 2-4 lines. Would the team prefer:
'regular'alias only'regular'alias + generic fallback for all unknown valuesI'd recommend (B) for robustness, but happy to go with whichever you prefer. 🙌
gaaclarke commentedon Jun 1, 2026
This sounds fine to me if you want to author a PR I could support that.
stuartmorgan-g commentedon Jul 14, 2026
Why isn't the option: "(C) Just add generic fallback for all unknown values"? Isn't the spec-required behavior that unknown values use the default? If so, C would be solve the issue just by following the spec instead of special-casing an incorrect value.
Yusufihsangorgel commentedon Jul 14, 2026
Following the (C) direction: flutter/packages#12199 now does exactly that — an unrecognized
font-weightfalls back tonormalFontWeightwith a warning (and still throws underwarningsAsErrors), per the CSS rule of ignoring an invalid value, soregularis handled without special-casing it.[vector_graphics_compiler] Ignore unrecognized font-weight values (fl…
github-actions commentedon Aug 11, 2026
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 -vand a minimal reproduction of the issue.