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?
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([]).
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.
Maybe it helps
final test = Map<String, int>(); test.putIfAbsent('58', () => 56);
if key doesn't exist, it will be putted into map.
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