mark-nicepants / figma2flutter

Converts design token json files to flutter
Apache License 2.0
17 stars 16 forks source link

[BUG] string.dart: isColorReference() does not identify color references #5

Closed freemansoft closed 8 months ago

freemansoft commented 8 months ago

:information_source: Info

Version: 0.2.0-alpha current head of the main branch

:speech_balloon: Description

Working on loading a set of JSON files instead of a single file. Ran into an issue with color. It uses the same regex used in other places and I think it is incorrect.

I added a print statement in isColorReference

  bool get isColorReference {
    bool isColor =
        !startsWith('{') && RegExp(r'{(.*?)}').firstMatch(this) != null;
    print('looking at $this to see if it is a color - $isColor');
    return isColor;
  }

Example output from this function with my test data. This is attempting to resolve a font size 10xl that is nested a couple deep

fontSize.10xl --> (fontSize.9xl and foundSize.Scale) fontSize.9xl --> (fontSize.base and fontSize.scale) fontSize.base has a value of 16

log trace shows that we don't see colors as colors but we still think 16 is a color outside of the color check and throw an exception when we can't find 16

looking at {color.white} to see if it is a color - false
looking at #ffffff to see if it is a color - false

ResolveTokenException{message: semantic.fontSize.10xl - Originating ResolveTokenException{message: Could not parse color for `16` originating from `semantic.fontSize.base`}}

looking at roundTo({semantic.fontSize.9xl} * {semantic.fontSize.scale}, 0) to see if it is a color - true
looking at roundTo({semantic.fontSize.base} * {semantic.fontSize.scale}^10, 0) to see if it is a color - true
looking at 16 to see if it is a color - false

:scroll: tokens file you tried to import

I'll put the json file in a PR https://github.com/mark-nicepants/figma2flutter/pull/4

freemansoft commented 8 months ago

Closed by PR https://github.com/mark-nicepants/figma2flutter/pull/4