getEdgeInsetsFromAttributes method
Implementation
EdgeInsets? getEdgeInsetsFromAttributes(
BuildContext context, String attributeKey) {
final attributes =
ComponentViewState.getData(context)?['attributes'] as Map?;
if (attributes != null) {
dynamic attributeValue = attributes[attributeKey];
if (attributeValue is String) {
if (attributeValue.startsWith('EdgeInsets.all(')) {
final trimedValue = attributeValue
.replaceAll("EdgeInsets.all(", "")
.replaceAll(")", "");
return EdgeInsets.all(double.tryParse(trimedValue) ?? 0);
} else if (attributeValue.startsWith('EdgeInsets(')) {
final trimedValue =
attributeValue.replaceAll("EdgeInsets(", "").replaceAll(")", "");
final parts = trimedValue.split(',');
return EdgeInsets.fromLTRB(
double.tryParse(parts[0]) ?? 0.0,
double.tryParse(parts[1]) ?? 0.0,
double.tryParse(parts[2]) ?? 0.0,
double.tryParse(parts[3]) ?? 0.0,
);
}
}
}
}