buildValue method

  1. @override
String buildValue(
  1. dynamic value
)
override

Builds the value for the specific type.

Make sure to only override this method with any new DesignTokenParser you create. Please avoid directly calling this method outside DesignTokenParser. Prefer DesignTokenParser.parse.

Implementation

@override
String buildValue(value) {
  if (value is String) {
    var opacity = 0.0;
    if (value.contains('%')) {
      opacity = parsePercentage(value);
    } else {
      try {
        opacity = double.parse(value);
      } catch (e) {
        throw Exception('Unable to parse opacity with data: $value');
      }
    }

    if (opacity < 0 || opacity > 1) {
      throw Exception(
        'Opacity value needs to be between 0 and 1. Current value: $value',
      );
    }

    return opacity.toString();
  }

  throw Exception('Unable to parse opacity with data: $value');
}