buildValue method
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) {
final radiiValues = value.split(' ');
final parseDimension = DimensionParser().parse;
switch (radiiValues.length) {
case 1:
final r = parseDimension(radiiValues[0]);
return 'BorderRadius.all(${_radius(r)})';
case 2:
final r1 = parseDimension(radiiValues[0]);
final r2 = parseDimension(radiiValues[1]);
return 'BorderRadius.only(topLeft: ${_radius(r1)}, topRight: ${_radius(r2)}, bottomLeft: ${_radius(r2)}, bottomRight: ${_radius(r1)})';
case 3:
final r1 = parseDimension(radiiValues[0]);
final r2 = parseDimension(radiiValues[1]);
final r3 = parseDimension(radiiValues[2]);
return 'BorderRadius.only(topLeft: ${_radius(r1)}, topRight: ${_radius(r2)}, bottomLeft: ${_radius(r2)}, bottomRight: ${_radius(r3)})';
case 4:
final r1 = parseDimension(radiiValues[0]);
final r2 = parseDimension(radiiValues[1]);
final r3 = parseDimension(radiiValues[2]);
final r4 = parseDimension(radiiValues[3]);
return 'BorderRadius.only(topLeft: ${_radius(r1)}, topRight: ${_radius(r2)}, bottomLeft: ${_radius(r4)}, bottomRight: ${_radius(r3)})';
default:
throw Exception(
'Cannot parse border radius since there are ${radiiValues.length} values. Please provide 1-4 values.',
);
}
}
throw Exception('Unable to parse border radius with data: $value');
}