mark-nicepants / figma2flutter

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

Fix Color Modifier Handling in Gradients #40

Closed apackin closed 6 days ago

apackin commented 1 week ago

Pull Request Description: Fix Color Modifier Handling in Gradients

Issue

References to colors in gradients currently drop the color modifier, leading to incorrect colors in gradients.

Solution

Abstract the modifier logic used in the ColorTransformer to a method within the ColorValue class. This allows the logic to be shared with the token parser reference resolver, ensuring consistent application of color modifications when that is supplied (as in the Gradient flow).

Changes

  1. New Method in ColorValue Class:

    • Introduced an applyStudioExtension method using the pre-existing logic nested in ColorTransfomer.transform.
  2. Integration into Token Parsing:

    • Updated _resolveColorValue and ColorTransformer to utilize the new method for applying extensions.
      // Updated _resolveColorValue
      final color = ColorValue.maybeParse(reference.value)
                          ?.applyStudioExtension(reference.extensions);
  3. Test Enhancements:

    • Added test coverage for alpha modifications to a gradient color.

Note

There is a potential improvement by always supplying a nullable extension when parsing ColorValues. However, further investigation of other usage scenarios is recommended before making this change more broadly.

freemansoft commented 6 days ago

LGTM