Flutter Unhandled error type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>'

Issue

When calling http.get using the Flutter http package, the following exception gets thrown:

Unhandled Exception: Unhandled error type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>' occurred in bloc Instance of 'AccountsBloc'.

The code which throws the exception

final response = await http.get(
  serverConfig.url,
  headers: _getHeaders(username, password),
);

Map<String, dynamic> _getHeaders(String username, String password) {
  return {
    "apikey": serverConfig.apiKey,
    "action": "login",
    "user": username,
    "pass": password
  };
}

It seems that _getHeaders() is causing this problem, when it’s called according to the console output.

Solution

try

Map<String, String> _getHeaders(String username, String password) {
  return {
    "apikey": serverConfig.apiKey,
    "action": "login",
    "user": username,
    "pass": password
  };
}

Answered By – Vilsad P P

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *