safeAsMap<T, V> method

Map<T, V>? safeAsMap<T, V>()

Implementation

Map<T, V>? safeAsMap<T, V>() {
  if (this is Map) {
    var origin = this as Map;
    if (origin.isEmpty) {
      return <T, V>{};
    }
    var realMap = <T, V>{};

    origin.forEach((key, value) {
      if (key is T && value is V) {
        realMap[key] = value;
      }
    });
    return realMap;
  } else {
    return null;
  }
}