getValue<T> method

T? getValue<T>(
  1. M key, [
  2. T? defaultValue
])

获取map value keymap->key defaultValue不在存在时返回默认值

Implementation

T? getValue<T>(M key, [T? defaultValue]) {
  if (this.isEmptyMap() || !(this?.containsKey(key) ?? false)) {
    return defaultValue;
  }
  Object? obj = this?[key];
  if (obj is! T) {
    return defaultValue;
  }
  T result = this?[key] as T;
  return result ?? defaultValue;
}