Flutter未处理的错误类型'_InternalLinkedHashMap <String,dynamic>'不是'Map <String,String>'类型的子类型

时间:2020-06-16 14:37:38

标签: flutter flutter-http

使用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()时,似乎导致了此问题。

1 个答案:

答案 0 :(得分:1)

尝试

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