Jelena Lecic
1 min readDec 19, 2019

--

Vladimir Tomić
Hm… coming from Java world, I don’t really use var but, I’ll try to explain:

void main() {
var json = {‘first’: ‘param1’, ‘second’: ‘param2’}; //json is Map<String,String>
json.putIfAbsent(‘third’, () => 12); //<- this will not compile
}

but, if you define json as a

Map<String, dynamic>

it will. Because map value can be String, or bool, or int … whatever.

I use dynamic mostly for networking, when I’m not sure what server response is going to be or what will body contain.. Mostly for some generic stuff.

Hope this helps :)

p.s.

You can use https://dartpad.dartlang.org/ for testing stuff like this.

--

--

No responses yet