user19635818
user19635818

Reputation: 23

How to print Map in dart console?

I have this Map of headers for sending http requests including cookies in header. I have log the changes data in console to make sure it is working.

This is my Map:

Map<String, String> headers = {};

I tried doing this but it is not working:

print(headers);

I am getting this message:

void print(Object? object)

Upvotes: 1

Views: 2667

Answers (2)

Louay Ghanney
Louay Ghanney

Reputation: 83

dart allow printing maps

check if you are printing headers map rather than something else

if you still have your problem maybe provide some code snippets ?enter image description here

Upvotes: 0

lepsch
lepsch

Reputation: 10319

You just need to print entry by entry from the Map.

It would be like the following example:

final headers = <String, String>{ 
  'AUTHORIZATION': 'test:test',
  'ACCEPT': 'application/json'
};

void main() {
  for (final e in headers.entries) {
    print('${e.key} = ${e.value}');
  }
}

OUTPUT

AUTHORIZATION = test:test
ACCEPT = application/json

Upvotes: 3

Related Questions