// ignore_for_file: avoid_print
import 'dart:convert';
import 'package:ftmovie/src/data/core/api_constants.dart';
import 'package:ftmovie/src/data/models/movie_model.dart';
import 'package:ftmovie/src/data/models/movies_result_model.dart';
import 'package:http/http.dart';
abstract class MovieRemoteDataSource {
Future<List<MovieModel>> getTrending();
}
class MovieRemoteDataSourceImpl extends MovieRemoteDataSource {
final Client _client;
MovieRemoteDataSourceImpl(this._client);
@override
Future<List<MovieModel>> getTrending() async {
final response = await _client.get(
'${ApiConstants.BASE_URL}trending/movie/day?api_key=${ApiConstants.API_KEY}',
headers: {
'Content-Type': 'application/json',
},
);
if (response.statusCode == 200){
final responseBody = json.decode(response.body);
final movies = MoviesResultModel.fromJson(responseBody).movies;
print(movies);
return movies;
} else {
throw Exception(response.reasonPhrase);
}
}
}
The part where I get the error: ‘${ApiConstants.BASE_URL}trending/movie/day?api_key=${ApiConstants.API_KEY}’, where the code is. I would appreciate your help.
I also asked my friends who know a little flutter. I tried everything they wrote on the internet, but I can’t print and see the data in any way.
2
Answers
get
takes anUri
object, not aString
. Fortunately it’s very easy to convert. Just writeyou can use static method of Uri class for parsing String to Uri like below: