getFieldAs<T> method
T?
getFieldAs<
T>( - String? fieldName, [
- T? def
])
Implementation
T? getFieldAs<T>(String? fieldName, [T? def]) {
var value = getField(fieldName);
if (value == null) return null;
if (T == String) {
return value as T;
} else if (T == int) {
return parseInt(value, def as int?) as T?;
} else if (T == double) {
return parseDouble(value, def as double?) as T?;
} else if (T == num) {
return parseNum(value, def as num?) as T?;
} else if (T == bool) {
return parseBool(value, def as bool?) as T?;
} else if (T == Decimal) {
return Decimal.parse(value) as T? ?? def;
} else if (T == DynamicInt) {
return DynamicInt.parse(value) as T? ?? def;
} else if (T == DynamicNumber) {
return DynamicNumber.parse(value) as T? ?? def;
} else {
return null;
}
}