summaryrefslogtreecommitdiff
path: root/lib/network/popular_api.dart
blob: 4d2c033797235598278825b6a26a2fad1197551c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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();
  }
}