Created
December 14, 2019 14:57
-
-
Save rrifafauzikomara/5e9087966add70d54da7aaf5820269bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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