'how to input text parameter to GET api with space
I have an http service to GET movies api data it works fine but if i input 2 words for example "The Batman" it's not working because it will return null but if i only input 1 word "Batman" it works fine, im still new with query query things
if you have the answer can you please answer with my full code ? because im quite slow to understand some logic
here is my code
Future searchMovie(movieName) async {
Uri url = Uri.parse('https://api.themoviedb.org/3/search/movie?api_key={key}&query=$movieName');
var response = await http.get(url);
if (response.statusCode == 200) {
List data = jsonDecode(response.body)['results'];
List<SearchMovieModel> searchedMovies = [];
for (var item in data) {
searchedMovies.add(SearchMovieModel.fromJson(item));
}
return searchedMovies;
} else {
throw Exception('Error get data');
}
}
Solution 1:[1]
you can try this way.
String query ='The Batman';
await get(Uri.parse('https://api.themoviedb.org/3/search/movie').replace(
queryParameters: {
'api_key' :'key',
'query' : query
}
));
Solution 2:[2]
URL encoded equivalent of space is %20 try The%20Batman
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hardik Mehta |
| Solution 2 | Eskandar Abedini |
