add method
Adds the attribute to the current style map.
If the attribute is an exclusive, it will remove
any other one that is also an exclusive.
Implementation
void add(EasyAttribute attribute) {
if (attribute.exclusive && attribute.value != null) {
bool hasExclusive = true;
// search first the knowed exclusive attributes
for (final EasyAttribute<Object?> exclusive
in EasyAttribute.exclusivesExceptHeader.values) {
if (attributes.containsKey(exclusive.key) &&
!exclusive.canMergeWith(attribute)) {
attributes.remove(exclusive.key);
hasExclusive = false;
break;
}
}
if (hasExclusive) {
for (String key in attributes.keys) {
final EasyAttribute<Object?>? value = attributes[key];
assert(value != null,
'value must be non null since is registered in ${toJson()}');
if (value!.exclusive && !value.canMergeWith(attribute)) {
attributes.remove(key);
break;
}
}
}
}
attribute.value == null
? remove(attribute.key)
: attributes[attribute.key] = attribute;
}