Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dart language: Map<Object,String> how to add new pair?

Tags:

map

dart

Given:

Map<WebSocket,String> mListUser; mListUser= new  Map<WebSocket,String>(); 

From what i understood now to add a new element i should just do:

mListUser[socket]="string"; 

instead im getting:

type 'String' is not a subtype of type 'int' of 'index'. 

What am i doing wrong?

like image 868
user1964154 Avatar asked Aug 11 '13 18:08

user1964154


People also ask

How do you Map objects in Dart?

In Dart Map, each key must be unique, but the same value can occur multiple times. The Map representation is quite similar to Python Dictionary. The Map can be declared by using curly braces {} ,and each key-value pair is separated by the commas(,). The value of the key can be accessed by using a square bracket([]).

How do you add data to a Map in flutter?

Add item to a Map in Dart/Flutter There are 2 way to add an item (key-value pair) to a Map: using square brackets [] calling putIfAbsent() method.


1 Answers

Maybe it helps

final test = Map<String, int>(); test.putIfAbsent('58', () => 56); 

if key doesn't exist, it will be putted into map.

like image 121
Вячеслав Францишко Avatar answered Sep 28 '22 12:09

Вячеслав Францишко