summaryrefslogtreecommitdiff
path: root/lib/network/popular_api.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/network/popular_api.dart')
-rw-r--r--lib/network/popular_api.dart19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/network/popular_api.dart b/lib/network/popular_api.dart
new file mode 100644
index 0000000..4d2c033
--- /dev/null
+++ b/lib/network/popular_api.dart
@@ -0,0 +1,19 @@
+import 'dart:convert';
+
+import 'package:http/http.dart' as http;
+import 'package:pmsna1/models/popular.dart';
+
+class PopularApi {
+ String apiKey = '0cb894064f40656f3575e8ccae3d8d73';
+ Uri get link => Uri.parse(
+ 'https://api.themoviedb.org/3/movie/popular?api_key=$apiKey&language=es-MX&page=1');
+
+ Future<List<Popular>?> getAllPopular() async {
+ http.Response result = await http.get(link);
+ var list = jsonDecode(result.body)['results'] as List;
+ if (result.statusCode != 200) {
+ return null;
+ }
+ return list.map((popular) => Popular.fromMap(popular)).toList();
+ }
+}