使用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()
时,似乎导致了此问题。
答案 0 :(得分:1)
尝试
Map<String, String> _getHeaders(String username, String password) {
return {
"apikey": serverConfig.apiKey,
"action": "login",
"user": username,
"pass": password
};
}