Skip to content

Instantly share code, notes, and snippets.

@ashishrawat2911
Created July 10, 2020 15:40
Show Gist options
  • Save ashishrawat2911/946ee2cd8ac3b4cd209ef556530103e9 to your computer and use it in GitHub Desktop.
Save ashishrawat2911/946ee2cd8ac3b4cd209ef556530103e9 to your computer and use it in GitHub Desktop.
import 'package:dio/dio.dart';
import 'package:network_handling/model/movie_response.dart';
import 'package:network_handling/services/api_result.dart';
import 'package:network_handling/services/dio_client.dart';
import 'package:network_handling/services/network_exceptions.dart';
class APIRepository {
DioClient dioClient;
final String _apiKey = "78b9f63937763a206bff26c070b94158";
String _baseUrl = "http://api.themoviedb.org/3/";
APIRepository() {
var dio = Dio();
dioClient = DioClient(_baseUrl, dio);
}
Future<ApiResult<List<Movie>>> fetchMovieList() async {
try {
final response = await dioClient
.get("movie/popular", queryParameters: {"api_key": _apiKey});
List<Movie> movieList = MovieResponse.fromJson(response).results;
return ApiResult.success(data: movieList);
} catch (e) {
return ApiResult.failure(error: NetworkExceptions.getDioException(e));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment