0

使用 Flutter http 包调用时http.get,会抛出以下异常:

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

抛出异常的代码

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
  };
}

_getHeaders()当根据控制台输出调用它时,似乎导致了这个问题。

4

1 回答 1

1

尝试

Map<String, String> _getHeaders(String username, String password) {
  return {
    "apikey": serverConfig.apiKey,
    "action": "login",
    "user": username,
    "pass": password
  };
}
于 2020-06-16T14:43:41.287 回答