I want to get a list of keys of a map in dart programming language.
I am familiar with dictionary in python and for the same objective in python there exists a direct method. I fail to find this in dart.
Is their any work around ?
A Dart Map allows you to get value by key. What about getting key by value? Using the keys property and the firstWhere() method of the List class, we can get key by specifying value . The Dart method firstWhere() iterates over the entries and returns the first one that satisfies the criteria or condition.
Initialize a Map with values in Dart/Fluttercreate a Map with all key/value pairs of other Map using from() , of() constructor. create a new Map from the given keys and values using fromIterables() . create Map in which keys and values are computed using fromIterable()
Dart map iterationforEach((key, val) { print('{ key: $key, value: $val}'); }); With forEach method, we print the key/value pairs of the fruit map.
void main() {
var details = {'Usrname':'tom','Password':'pass@123'};
print(details.keys); \\ Gives an Iterable<String>.
\\ And to return a true List:
List newList = details.keys.toList();
}
(Usrname, Password)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With