I am new to flutter and encountered this error. the app started to install but during the instalation this error will show "_TypeError (type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String')"
Future<Map> getParsedReverseGeocoding(LatLng latLng) async {
var response =
json.decode(await getReverseGeocodingGivenLatLngUsingMapbox(latLng));
Map feature = response['features'][0];
Map revGeocode = {
'name': feature['text'],
'address': feature['place_name'].split('${feature['text']}, ')[1],
'place': feature['place_name'],
'location': latLng
};
return revGeocode;
}
Future getReverseGeocodingGivenLatLngUsingMapbox(LatLng latLng) async {
String query = '${latLng.longitude},${latLng.latitude}';
String url = '$baseUrl/$query.json?access_token=$accessToken';
url = Uri.parse(url).toString();
print(url);
try {
_dio.options.contentType = Headers.jsonContentType;
final responseData = await _dio.get(url);
return responseData.data;
} catch (e) {
final errorMessage = DioExceptions.fromDioError(e as DioError).toString();
debugPrint(errorMessage);
}
}
CodePudding user response:
Since you set the content type to Headers.jsonContentType
(which is the default I think) the decoding is done by dio
. Simply remove json.decode
:
var response = await getReverseGeocodingGivenLatLngUsingMapbox(latLng);