Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of keys of a map in dart?

Tags:

flutter

dart

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 ?

like image 631
Kshitij dhyani Avatar asked Jun 10 '19 08:06

Kshitij dhyani


People also ask

How do I get the Dart map key?

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.

How do you get map keys in Flutter?

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()

How do I print a Dart key and value?

Dart map iterationforEach((key, val) { print('{ key: $key, value: $val}'); }); With forEach method, we print the key/value pairs of the fruit map.


1 Answers

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)

like image 190
Ahmad Sattout Avatar answered Oct 13 '22 22:10

Ahmad Sattout