dart:core 库中Map.from 的用法介绍如下。
用法:
Map<K, V>.from(
Map other
)
创建一个具有与 other 相同的键和值的 LinkedHashMap。
键必须都是 K 的实例和 V 的值。 other 映射本身可以具有任何类型,与 Map.of 不同,并且在运行时检查键和值类型(并且可能失败)。
在可能的情况下更喜欢使用Map.of,并且只使用Map.from 创建一个具有比原始类型更精确类型的新映射,并且知道所有键和值都具有这些更精确的类型。
LinkedHashMap 需要 key 来实现兼容的 operator== 和 hashCode 。它以 key 插入顺序进行迭代。
final planets = <num, String>{1: 'Mercury', 2: 'Venus', 3: 'Earth', 4: 'Mars'};
final mapFrom = Map<int, String>.from(planets);
print(mapFrom); // {1: Mercury, 2: Venus, 3: Earth, 4: Mars}
相关用法
- Dart Map.fromIterable用法及代码示例
- Dart Map.fromIterables用法及代码示例
- Dart Map.fromEntries用法及代码示例
- Dart Map.forEach用法及代码示例
- Dart Map.update用法及代码示例
- Dart Map.addEntries用法及代码示例
- Dart Map.removeWhere用法及代码示例
- Dart Map.remove用法及代码示例
- Dart Map.containsValue用法及代码示例
- Dart Map.clear用法及代码示例
- Dart Map.containsKey用法及代码示例
- Dart Map.updateAll用法及代码示例
- Dart Map.unmodifiable用法及代码示例
- Dart Map.putIfAbsent用法及代码示例
- Dart Map.of用法及代码示例
- Dart Map.addAll用法及代码示例
- Dart MapMixin.containsKey用法及代码示例
- Dart MapEntry.value用法及代码示例
- Dart MapMixin.update用法及代码示例
- Dart MapView.containsValue用法及代码示例
- Dart MapMixin.putIfAbsent用法及代码示例
- Dart MapMixin.addAll用法及代码示例
- Dart MapMixin.clear用法及代码示例
- Dart MapMixin.addEntries用法及代码示例
- Dart MapView.clear用法及代码示例
注:本文由纯净天空筛选整理自dart.dev大神的英文原创作品 Map<K, V>.from constructor。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
