I have been creating an application and have been stuck at this problem for the last 2 days without any progress. While fetching the data from the internet the http.get request is giving me an exception. This is the Rapid API (IMDB) I am trying to integrate into my application. I will provide you my code for a better understanding.
Here is the get request:
class NetworkGetRequest {
static Future<Map<String, Object>> getRequestWithQueryParameter(Map<String, dynamic> queryParameters, String url) async {
Map<String, Object> result = new Map();
final headers = {
"content-type": "application/json",
"x-rapidapi-key": <YOUR-API-KEY>,
"x-rapidapi-host": "movie-database-imdb-alternative.p.rapidapi.com",
"useQueryString": true
};
try {
final uri = Uri.https(url, "", queryParameters);
var response = await http.get(uri, headers: headers);
Map<String, Object> responseMap = jsonDecode(response.body);
result['data'] = responseMap;
return result;
} catch (e) {
result['error'] = 'Exception : ' + e.toString();
return result;
}
}
This is how I am calling the API:
Map<String, Object> result = new Map();
Map<String, dynamic> queryParam = {
'i': 'tt12361974',
'r': 'json',
'plot': 'full'
};
String url = 'movie-database-imdb-alternative.p.rapidapi.com';
result = await NetworkGetRequest.getRequestWithQueryParameter(queryParam, URL);
And this is the Exception I am getting from it:
type '_InternalLinkedHashMap<String, Object>' is not a subtype of type 'Map<String, String>?'
And this the JSON I am expecting from the server:
{
"Title": "Zack Snyder's Justice League",
"Year": "2021",
"Rated": "R",
"Released": "18 Mar 2021",
"Runtime": "242 min",
"Genre": "Action, Adventure, Fantasy",
"Director": "Zack Snyder",
"Writer": "Jerry Siegel, Joe Shuster, Zack Snyder",
"Actors": "Henry Cavill, Ben Affleck, Gal Gadot",
"Plot": "Determined to ensure Superman's ultimate sacrifice was not in vain, Bruce Wayne aligns forces with Diana Prince with plans to recruit a team of metahumans to protect the world from an approaching threat of catastrophic proportions. The task proves more difficult than Bruce imagined, as each of the recruits must face the demons of their own pasts to transcend that which has held them back, allowing them to come together, finally forming an unprecedented league of heroes. Now united, Batman, Wonder Woman, Aquaman, Cyborg and The Flash may be too late to save the planet from Steppenwolf, DeSaad and Darkseid and their dreadful intentions.",
"Language": "English, Icelandic, French",
"Country": "United States, United Kingdom",
"Awards": "1 nomination",
"Poster": "https://m.media-amazon.com/images/M/MV5BYjI3NDg0ZTEtMDEwYS00YWMyLThjYjktMTNlM2NmYjc1OGRiXkEyXkFqcGdeQXVyMTEyMjM2NDc2._V1_SX300.jpg",
"Ratings": [
{
"Source": "Internet Movie Database",
"Value": "8.1/10"
},
{
"Source": "Metacritic",
"Value": "54/100"
}
],
"Metascore": "54",
"imdbRating": "8.1",
"imdbVotes": "308,599",
"imdbID": "tt12361974",
"Type": "movie",
"DVD": "N/A",
"BoxOffice": "N/A",
"Production": "N/A",
"Website": "N/A",
"Response": "True"
}