getModification<T> method
Get Modification
key : the name of the key relative to modification defaultValue: the returned value if the key is not found
Implementation
T getModification<T>(String key, T defaultValue, {bool activate = false}) {
var ret = defaultValue;
if (!this.decisionManager.isPanic() &&
this.modifications.containsKey(key)) {
try {
var modification = this.modifications[key];
if (modification == null) {
print("Modification value is null, will return default value");
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;
}
print(
"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;
}
print(
"Modification value ${modification.value} type ${modification.value.runtimeType} cannot be casted as $T, will return default value");
break;
}
if (activate) {
/// send activate later
_sendActivate(modification);
}
} catch (exp) {
print("an exception raised $exp , will return a default value ");
}
}
return ret;
}