encodeAlignment static method
Encodes the given value
to either a String representation of the
Alignment or a JSON map that follows the structure:
{
"x": "<double>",
"y": "<double>"
}
Supported string values are:
bottomCenter
bottomLeft
bottomRight
center
centerLeft
centerRight
topCenter
topLeft
topRight
All other values, including null
, will result in null
.
Implementation
static dynamic encodeAlignment(Alignment? value) {
dynamic result;
if (value != null) {
if (value.x == Alignment.bottomCenter.x &&
value.y == Alignment.bottomCenter.y) {
result = 'bottomCenter';
} else if (value.x == Alignment.bottomLeft.x &&
value.y == Alignment.bottomLeft.y) {
result = 'bottomLeft';
} else if (value.x == Alignment.bottomRight.x &&
value.y == Alignment.bottomRight.y) {
result = 'bottomRight';
} else if (value.x == Alignment.center.x &&
value.y == Alignment.center.y) {
result = 'center';
} else if (value.x == Alignment.centerLeft.x &&
value.y == Alignment.centerLeft.y) {
result = 'centerLeft';
} else if (value.x == Alignment.centerRight.x &&
value.y == Alignment.centerRight.y) {
result = 'centerRight';
} else if (value.x == Alignment.topCenter.x &&
value.y == Alignment.topCenter.y) {
result = 'topCenter';
} else if (value.x == Alignment.topLeft.x &&
value.y == Alignment.topLeft.y) {
result = 'topLeft';
} else if (value.x == Alignment.topRight.x &&
value.y == Alignment.topRight.y) {
result = 'topRight';
} else {
result = {
'x': value.x,
'y': value.y,
};
}
}
return _stripDynamicNull(result);
}