Flutter Get Key от карты
String key = values.keys.elementAt(index);
loonix
String key = values.keys.elementAt(index);
void main() {
final testMap = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5};
for (final mapEntry in testMap.entries) {
final key = mapEntry.key;
final value = mapEntry.value;
print('Key: $key, Value: $value'); // Key: a, Value: 1 ...
}
}
String value = myMap["mykey"];
// adding keys
var colors = new Map();
colors['blue'] = false;
colors['red'] = true;
print(colors);
// curly bracket literals can also be used:
var shapes = {
'square': false,
'triangle': true
};
print(shapes);
// keys and values can be iterated.
// HashMap iterates in arbitrary order, while LinkedHashMap, and SplayTreeMap
// iterate in the order they were inserted into the map.
for (var key in shapes.keys) print(key);
for (var value in shapes.values) print(value);
}