Skip to content

Instantly share code, notes, and snippets.

@rrifafauzikomara
Created December 14, 2019 14:57
Show Gist options
  • Save rrifafauzikomara/5e9087966add70d54da7aaf5820269bf to your computer and use it in GitHub Desktop.
Save rrifafauzikomara/5e9087966add70d54da7aaf5820269bf to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:http/http.dart' show Client;
import 'dart:convert';
import 'package:network/model/movie.dart';
class ApiProvider {
Client client = Client();
static final _apiKey = 'Your_API_Key';
static final String _baseUrl = 'http://api.themoviedb.org/3/movie';
Future<Movie> getMovieList() async {
final response = await client.get("$_baseUrl/popular?api_key=$_apiKey");
if (response.statusCode == 200) {
return Movie.fromJson(json.decode(response.body));
} else {
throw Exception('Failed to load movie');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment