valueFromKey<U> static method

U valueFromKey<U>(
  1. Map<String, dynamic> data,
  2. String key, {
  3. 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;
}