Skip to content

Instantly share code, notes, and snippets.

@jmolins
Created December 1, 2018 13:45
Show Gist options
  • Save jmolins/40458686d0c3e1c5cf01c25e1eb4d607 to your computer and use it in GitHub Desktop.
Save jmolins/40458686d0c3e1c5cf01c25e1eb4d607 to your computer and use it in GitHub Desktop.
////////////////////////////////////
////// api_key.dart
////////////////////////////////////
String key = "..............................";
////////////////////////////////////
////// config.dart
////////////////////////////////////
import 'package:devfest_asturias/api_key.dart';
String popularUrl({int page = 1}) =>
"https://api.themoviedb.org/3/movie/popular?api_key=$key&page=$page";
////////////////////////////////////
////// api.dart
////////////////////////////////////
import 'dart:convert';
import 'package:devfest_asturias/config.dart';
import 'package:devfest_asturias/movie.dart';
import 'package:http/http.dart' as http;
Future<List<Movie>> getMovies({int page}) async {
http.Response resp = await http.get(popularUrl(page: page));
Map<String, dynamic> hash = json.decode(resp.body);
List<dynamic> lista = hash['results'];
return lista.map((movie) => Movie.fromJson(movie)).toList();
}
////////////////////////////////////
////// movie.dart
////////////////////////////////////
class Movie {
final String title;
final String overview;
Movie(this.title, this.overview);
Movie.fromJson(Map<String, dynamic> json)
: title = json['title'],
overview = json['overview'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment