valueFromKey<U> static method
U
valueFromKey<
U>( - Map<String, dynamic> data,
- String key, {
- required U defaultValue,
})
Implementation
static U valueFromKey<U>(
Map<String, dynamic> data,
String key, {
required U defaultValue,
}) {
final dynamic value = data[key];
if (U.toString() == 'int') {
if (value is double) {
return value.toInt() as U;
}
} else if (U.toString() == 'double') {
if (value is int) {
return value.toDouble() as U;
}
}
if (value == null) {
return defaultValue;
}
return value as U;
}