figma2flutter
figma2flutter copied to clipboard
[BUG] Returning 0.0 creates silent defects
:information_source: Info
Version: 0.2.1-alpha
:speech_balloon: Description
Returning 0 for unparsable values is really a silent failure that gives you bad values in the generated code. Code like this should IMO throw a ProcessTokenException or a FormatException
double _parseNum(String value) {
// 1px = 1.0
if (value.endsWith('px')) {
return double.tryParse(value.substring(0, value.length - 2)) ?? 0;
}
// 1rem = 16px (base font size)
if (value.endsWith('rem')) {
return (double.tryParse(value.substring(0, value.length - 3)) ?? 0) *
kBaseFontSize;
}
// 100% = 1.0
// 50% = 0.5
if (value.endsWith('%')) {
return (double.tryParse(value.substring(0, value.length - 1)) ?? 0) / 100;
}
return double.tryParse(value) ?? 0;
}
:scroll: tokens file you tried to import
Importing a token for something like always returns 0.0 because of the missing space between "*" and "2". It doesn't think there is a math operator so it parses them as a number and if that is null it returns zero.
"sizing-base": {
"value": "16 *2",
"type": "sizing"
},