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

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

使用 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() 导致了这个问题。

尝试

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