getModification<T> method
T
getModification<
T>( - String key,
- T defaultValue, {
- bool activate = false,
})
override
Implementation
@override
T getModification<T>(String key, T defaultValue, {bool activate = false}) {
var ret = defaultValue;
bool hasSameType =
true; // When the Type is not the same the activate won't be sent
if (visitor.modifications.containsKey(key)) {
try {
var modification = visitor.modifications[key];
if (modification == null) {
Flagship.logger(
Level.INFO, GET_MODIFICATION_ERROR.replaceFirst("%s", key));
return ret;
}
switch (T) {
case double:
if (modification.value is double) {
ret = modification.value as T;
break;
}
if (modification.value is int) {
ret = (modification.value as int).toDouble() as T;
break;
}
Flagship.logger(Level.INFO,
"Modification value ${modification.value} type ${modification.value.runtimeType} cannot be casted as $T, will return default value");
break;
default:
if (modification.value is T) {
ret = modification.value as T;
break;
}
hasSameType = false;
Flagship.logger(Level.INFO,
"Modification value ${modification.value} type ${modification.value.runtimeType} cannot be casted as $T, will return default value");
break;
}
if (activate && hasSameType) {
// Send activate later
_sendActivate(modification);
}
} catch (exp) {
Flagship.logger(Level.INFO,
"an exception raised $exp , will return a default value ");
}
}
return ret;
}